So I have a fairly simple stack I'm trying to setup consisting of a single Lambda function subscribed to an SNS topic. I'd like to use CodePipeline with three stages: Source (GitHub) -> Build (CodeBuild) -> Deploy (CloudFormation).
I managed to cobble together a template and buildspec file that that work, except I'm lost on how I'm supposed to reference the output artifact that CodeBuild makes in the CloudFormation template; right now I just have placeholder inline code.
Basically, what am I supposed to put in the Code:
property of the Lambda function in order to get the CodeBuild files (which is my output artifact in CodePipeline)?
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'
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/*
AWS::CodePipeline::Pipeline
andAWS::CodeBuild::Project
resources in your CloudFormation template. – MaiKaY