【问题标题】:CloudFormation Pseudo ParametersCloudFormation 伪参数
【发布时间】:2019-09-19 19:59:41
【问题描述】:

我正在创建一个 AWS CodeStar 项目并创建了我的 template.yml,其中包含我的 Lambda 函数、SF、DynamoDB 表。

如果我输入区域和硬编码的帐户 ID,它可以工作,但是当我用 ${AWS::Region}${AWS::AccountId} 之类的参数替换它们时,我会收到以下错误:

未能执行更改集。当前堆栈状态:UPDATE_ROLLBACK_COMPLETE。原因:未提供任何原因。

这是我template.yml的一部分

Resources:

  DataAgentIntercept:
    Type: AWS::StepFunctions::StateMachine
    Properties:
      StateMachineName: DataAgentIntercept
      DefinitionString: |-
        {
          "StartAt": "InsertAgentDataDB",
          "States": {
            "InsertAgentDataDB": {
              "Type": "Task",
              "Resource": "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:awscodestar-pocawsjawa-lambda-InsertAgentDataDB-10UOAYKYNWLYB",
              "End": true
            }
          }
        }
      RoleArn: arn:aws:iam::${AWS::AccountId}:role/service-role/StatesExecutionRole-eu-west-1

我做错了什么?

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    默认情况下,字符串只是文字值。如果你想执行任何替换,你需要使用Fn::Sub(在YAML中你可以使用简写notaiton!Sub):

      StateMachineName: DataAgentIntercept
      DefinitionString: !Sub |-
        {
          "StartAt": "InsertAgentDataDB",
          "States": {
            "InsertAgentDataDB": {
              "Type": "Task",
              "Resource": "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:awscodestar-pocawsjawa-lambda-InsertAgentDataDB-10UOAYKYNWLYB",
              "End": true
            }
          }
        }
      RoleArn: !Sub "arn:aws:iam::${AWS::AccountId}:role/service-role/StatesExecutionRole-eu-west-1"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-30
      • 2021-07-20
      • 2018-05-30
      • 2019-01-06
      • 2019-07-02
      • 1970-01-01
      • 2019-09-30
      • 2021-06-10
      相关资源
      最近更新 更多