所以我有一个相当简单的堆栈,我正在尝试设置一个由订阅 SNS 主题的单个 Lambda 函数组成的堆栈。我想使用具有三个阶段的 CodePipeline:Source (GitHub) -> Build (CodeBuild) -> Deploy (CloudFormation)。
我设法拼凑了一个可以工作的模板和构建规范文件,除了我不知道应该如何引用 CodeBuild 在 CloudFormation 模板中制作的输出工件;现在我只有占位符内联代码。
Code:
基本上,为了获取 CodeBuild 文件(这是我在 CodePipeline 中的输出工件),我应该在 Lambda 函数的属性中添加什么?
模板.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'
Properties:
FunctionName: !GetAtt
- LambdaFunction
- Arn
Action: 'lambda:InvokeFunction'
Principal: sns.amazonaws.com
SourceArn: !Ref SNSTopic
buildspec.yml:
version: 0.2
phases:
install:
commands:
- pip install -r requirements.txt -t libs
artifacts:
type: zip
files:
- template.yml
- main.py
- lib/*