CodePipeline找不到我YAML模板

时间:2019-01-31 10:59:05

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

我建立使用AWS CodePipeline一个CD管道。我通过使用S3存储桶作为管道源来获取YAML模板,然后将其作为输出工件推送到部署阶段,作为输入工件。

我现在面临的问题是CodePipeline加密YAML模板,并把它放在S3神器店,所以当CloudFormation长相输入artifactory的它确实找到该文件,因为它的名字被改变,所以如何从加密artifactory的停止管道?

下面是我的CodePipeline CloudFormation模板:

Resources:
  ArtifactStoreBucket:
    Type: AWS::S3::Bucket
    Properties:
      VersioningConfiguration:
        Status: Enabled

  Pipeline:
    Type: AWS::CodePipeline::Pipeline
    Properties:

      ArtifactStore:
        Location: !Ref 'ArtifactStoreBucket'
        Type: S3

      DisableInboundStageTransitions: []

      Name: !Ref 'PipelineName'

      RoleArn: !GetAtt [PipelineRole, Arn]

      Stages:

        - Name: S3Source
          Actions:
          - Name: TemplateSource
            ActionTypeId:
              Category: Source
              Owner: AWS
              Provider: S3
              Version: '1'
            Configuration:
              S3Bucket: !Ref 'S3Bucket'
              S3ObjectKey: !Ref 'CFNTemplateName'
            OutputArtifacts:
              - Name: TemplateSource
                EncryptionDisabled: true
            RunOrder: '1'    

        - Name: DeployToTest
          Actions:
            - Name: CreateChangeSetTest
              ActionTypeId:
                Category: Deploy
                Owner: AWS
                Version: 1
                Provider: CloudFormation
              Configuration:
                ChangeSetName: sample-lambda-dev
                ActionMode: CHANGE_SET_REPLACE
                StackName: sample-lambda-dev
                Capabilities: CAPABILITY_NAMED_IAM
                TemplatePath: !Sub "TemplateSource2::${CFNTemplateName}"
                RoleArn: !GetAtt [CFNRole, Arn]
              RunOrder: 1

            - Name: DeployChangeSetTest
              ActionTypeId:
                Category: Deploy
                Owner: AWS
                Version: 1
                Provider: CloudFormation
              Configuration:
                ChangeSetName: sample-lambda-dev
                ActionMode: CHANGE_SET_EXECUTE
                StackName: sample-lambda-dev
                RoleArn: !GetAtt [CFNRole, Arn]
              RunOrder: 2

我确信我提供正确的神器和正确的模板名称。

2 个答案:

答案 0 :(得分:0)

在此行:

  

TemplatePath:!Sub“ TemplateSource2 :: $$ CFNTemplateName}”

是工件,名为TemplateSource2-但是您的模板中没有定义输出工件TemplateSource2。必须重命名。

对于CFNTemplateName:您已经在源代码部分中使用它来定义在s3上找到工件( zip文件)的位置

声明TemplatePath时,您引用了工件并声明了该工件内的路径。

docs

  

AWS CloudFormation模板文件的位置,其格式为ArtifactName :: TemplateFileName。

像这样更新此行:

  

TemplatePath:!Sub“ TemplateSource :: your / path / inside / the / zip / file”

答案 1 :(得分:0)

CreateChangeSetTest操作中存在两个问题:

1)它缺少输入工件部分-您必须声明每个操作可用的工件。 2)工件的名称错误-您在源阶段定义了TemplateSource输出工件,但是您使用的是TemplateSource2名称。

将步骤更改为以下内容:

            - Name: CreateChangeSetTest
          ActionTypeId:
            Category: Deploy
            Owner: AWS
            Version: 1
            Provider: CloudFormation
          Configuration:
            ChangeSetName: sample-lambda-dev
            ActionMode: CHANGE_SET_REPLACE
            StackName: sample-lambda-dev
            Capabilities: CAPABILITY_NAMED_IAM
            TemplatePath: !Sub "TemplateSource::${CFNTemplateName}"
            RoleArn: !GetAtt [CFNRole, Arn]
          RunOrder: 1
          InputArtifacts:
            - Name: TemplateSource