小编mth*_*mth的帖子

如何在CloudFormation中使用CodeBuild的输出工件?

所以我有一个相当简单的堆栈我正在尝试设置由一个订阅SNS主题的Lambda函数组成.我想使用CodePipeline有三个阶段:Source(GitHub) - > Build(CodeBuild) - > Deploy(CloudFormation).

我设法凑齐了一个模板和buildspec文件,这是有效的,除了我失去了我应该如何引用CodeBuild在CloudFormation模板中产生的输出工件; 现在我只有占位符内联代码.

基本上,Code:为了获得CodeBuild文件(这是我在CodePipeline中的输出工件),我应该放在Lambda函数的属性中?

template.yml:

AWSTemplateFormatVersion: 2010-09-09
Resources:
  SNSTopic:
    Type: 'AWS::SNS::Topic'
    Properties:
      Subscription:
        - Endpoint: !GetAtt
            - LambdaFunction
            - Arn
          Protocol: lambda
  LambdaFunction:
    Type: 'AWS::Lambda::Function'
    Properties:
      Runtime: python3.6
      Handler: main.lamda_handler
      Timeout: '10'
      Role: !GetAtt
        - LambdaExecutionRole
        - Arn
      Code:
        ZipFile: >
          def lambda_handler(event, context):
            print(event)
            return 'Hello, world!'
  LambdaExecutionRole:
    Type: 'AWS::IAM::Role'
    Properties:
      AssumeRolePolicyDocument:
        Version: 2012-10-17
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - lambda.amazonaws.com
            Action:
              - 'sts:AssumeRole'
      ManagedPolicyArns:
        - 'arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole'
  LambdaInvokePermission:
    Type: 'AWS::Lambda::Permission' …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services aws-cloudformation aws-codepipeline aws-codebuild

10
推荐指数
1
解决办法
3835
查看次数