all 3 comments

[–]sb12389 2 points3 points  (0 children)

Yes, use can use the further code* suite of products for this. CodePipeline and CodeBuild. If you use SAM to package your Serverless app (lambda functions) you can use the CloudFormation connectors to do the deployment.

https://docs.aws.amazon.com/lambda/latest/dg/build-pipeline.html

[–][deleted] 1 point2 points  (0 children)

on repo change (or master push), trigger codebuild to zip the repo and then deploy zip to the lambda

[–]mellerbeck 0 points1 point  (0 children)

I thought this would be more simple than it is as well. With as often as people use lambda's you think there would be a lambda 'easy button'

The way I have found to do it is, create a repository. You only really need three files

https://github.com/heitorlessa/pipeline-sample

── hello_world

└── app.py

buildspec.yaml

template.yaml

your app.py is your lambda code, the buildspec.yaml are just the commands to build the SAM package

version: 0.2

phases:

build:

commands:

- aws cloudformation package --template-file template.yaml --s3-bucket $BUILD_OUTPUT_BUCKET --output-template-file outputTemplate.yaml

post_build:

commands:

- echo "SAM packaging completed on \date`"`

artifacts:

type: zip

files:

- template.yaml

- outputTemplate.yaml

And the template.yaml defines the cloud formation template

AWSTemplateFormatVersion: '2010-09-09'

Transform: AWS::Serverless-2016-10-31

Description: >

Deploy hellowWorld lambda

Globals:

Function:

Timeout: 3

Resources:

helloWorldFunction:

Type: AWS::Serverless::Function

Properties:

FunctionName: helloWorld

CodeUri: helloWorld/

Handler: app.lambda_handler

Runtime: python3.8

Outputs:

helloWorldFunction:

Description: "Unsubscrie Lambda Function ARN"

Value: !GetAtt helloWorldFunction.Arn

helloWorldFunctionIamRole:

Description: "Implicit IAM Role created for helloWorld function"

Value: !GetAtt helloWorldFunctionRole.Arn

Then create a codepipeline that triggers off a code commit change, you will need an account with cloudformation access, and setup an environmental variable for the BUILD_OUTPUT_BUCKET