CloudFormation从CodePipeline传递参数

时间:2017-09-16 04:55:04

标签: amazon-web-services amazon-cloudformation aws-codepipeline

我有SAM应用程序和CodePipeline设置来部署它。我想将参数从我的管道传递到SAM的YAML文件中。我尝试使用ParameterOverrides,但似乎仍然得到:

  

参数:[AppName]必须具有值(服务:AmazonCloudFormation;状态代码:400;错误代码:ValidationError;请求ID:46d1dfd6-9a9a-11e7-a59d-999618d6a174)

我的sam.yml参数definations

AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Parameters:
  AppName:
    Type: String
    Description: Prefix for resources

定义参数的部分覆盖:

    - Name: ExecuteChangeSet
      Actions:
      - Name: Lambda
        ActionTypeId:
          Category: Deploy
          Owner: AWS
          Version: 1
          Provider: CloudFormation
        Configuration:
          ActionMode: CHANGE_SET_EXECUTE
          ChangeSetName: !Sub
            - '${PipelineName}-lambda'
            - {PipelineName: !Ref PipelineName}
          StackName: !Sub
            - '${PipelineName}-lambda'
            - {PipelineName: !Ref PipelineName}
          ParameterOverrides: !Sub '{"AppName": "${PipelineName}-lambda"}'

这有什么不对吗?

1 个答案:

答案 0 :(得分:3)

您似乎在ParameterOverrides操作模式期间尝试应用CHANGE_SET_EXECUTE。如果我没有弄错,那么这会映射到CloudFormations ExecuteChangeSet操作,该操作没有Parameters属性。

解决方法是在创建更改集时应用参数。这将在CodePipeline中使用CHANGE_SET_REPLACE操作模式完成。或者,您可以查看CREATE_UPDATE。查看AWS CloudFormation Configuration Properties了解详情。

这是一个创建,然后执行更改集

的示例
- Name: CreateChangeSet
  Actions:
    - Name: Lambda
      ActionTypeId:
        Category: Deploy
        Owner: AWS
        Version: 1
        Provider: CloudFormation
      InputArtifacts:
        - Name: BuildOutputArtifact
      Configuration:
        ActionMode: CHANGE_SET_REPLACE
        ChangeSetName: !Sub
          - '${PipelineName}-lambda'
          - {PipelineName: !Ref PipelineName}
        StackName: !Sub
          - '${PipelineName}-lambda'
          - {PipelineName: !Ref PipelineName}
        ParameterOverrides: !Ref ProjectParameterOverrides
        TemplatePath: BuildOutputArtifact::SamDeploymentTemplate.yaml
- Name: ExecuteChangeSet
  Actions:
  - Name: Lambda
    ActionTypeId:
      Category: Deploy
      Owner: AWS
      Version: 1
      Provider: CloudFormation
    Configuration:
      ActionMode: CHANGE_SET_EXECUTE
      ChangeSetName: !Sub
        - '${PipelineName}-lambda'
        - {PipelineName: !Ref PipelineName}
      StackName: !Sub
        - '${PipelineName}-lambda'
        - {PipelineName: !Ref PipelineName}