3

我有一個SAM應用程序和一個CodePipeline設置來部署它。我想從Pipeline傳遞參數到SAM的YAML文件中。我試着用ParameterOverrides但似乎仍然得到:從CodePipeline傳遞參數的CloudFormation

參數:[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"}' 

這是什麼問題?

回答

2

看起來您正試圖在CHANGE_SET_EXECUTE操作模式期間應用ParameterOverrides。如果我沒弄錯,在引擎蓋下,這將映射到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}