amazon-web-services - 如何输出 IAM 角色并在另一个堆栈中使用它?

标签 amazon-web-services aws-cloudformation

我有两个堆栈,分别名为“createIAMRole”“createElasticSearch”“createdLambda”。我想要的是,我想在 “createElasticSearch”“createdLambda” 中使用名为 “createIAMRole” 的第一个堆栈中的 IAM 角色 ARN。

创建IAM角色

AWSTemplateFormatVersion: '2010-09-09'
Description: >
  blah.

Resources:
  myIAMRole:
    Type: AWS::IAM::Role
    Properties:
      ..
      ..
      Policies:
        - PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: Allow
                Action:
                  - dynamodb:*
                Resource: "*"
          PolicyName: "myIAMRolePolicy"

Outputs:
  myIAMRole:
    Description: myIAMRole to use Stacks
    Value: !Ref myIAMRole

“创建ElasticSearch”

Resources:
  ElasticsearchDomain:
    Type: AWS::Elasticsearch::Domain
    Properties:
      ..
      ..
      AccessPolicies:
        Version: "2012-10-17"
        Statement:
          - Effect: "Allow"
            Principal:
              AWS: 
                - >>> THERE IS I WANT TO ADD <<<
            Action: "es:*"
            Resource: "*"
      AdvancedOptions:
        rest.action.multi.allow_explicit_index: "true"

请告诉我该怎么做,谢谢。

最佳答案

For the createIAMRole you need to export the output: 
Outputs:   myIAMRole:
    Description: myIAMRole to use Stacks
    Value: !Ref myIAMRole
    Export:
      Name: myIAMRole

And for the createElasticSearch you need to "ImportValue": 
Fn::ImportValue:
   !Sub "${myIAMStackName}-myIAMRole"

More Information: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-importvalue.html

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/outputs-section-structure.html

关于amazon-web-services - 如何输出 IAM 角色并在另一个堆栈中使用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59748761/

相关文章:

amazon-web-services - 将 GetObject (v2) 迁移到 GetObjectCommand (v3) - aws-sdk

java - 尝试使用 Java SDK 将文件放入 AWS Device Farm 时出现 "Invalid application uploaded"

amazon-web-services - 在 Cloudformation 的 Lambda 定义的 Events 属性中创建 API 端点时,如何获取 API 端点的 URL

amazon-web-services - 无服务器图像处理程序 - 如何将子文件夹设置为根目录

amazon-web-services - 使用授权者后出现 AWS Amplify API Gateway cors 错误 : aws_iam

amazon-web-services - 无法从 CloudFormation yaml 创建多个 S3 存储桶

amazon-web-services - 从 SecretsManager 加载的分割字符串

amazon-web-services - CloudFormation 可以从快照创建 AMI

python-3.x - 使用 Python Boto3 从 Cloudformation 输出中获取 KeyValue

amazon-web-services - aws cloudformation 用户数据 : how to use local variable in script