Deploy a Lambda function triggered by S3 event using CodePipeline
Yinlin Chen
Posted on April 3, 2020
This post demonstrates how to deploy a Lambda function hosted in the GitHub using CodePipeline. We use one of our projects S3toDDB as an example. The Lambda function in this project receives event notifications from a S3 bucket, process data in files, and create or update data in DynamoDB. Please see project README for details.
Go to the CodePipeline console and select “create pipeline”.
In the Step 1:
- Enter a pipeline name
- Under service role, select new service role and enter a role name, click Next button.
In the Step 2:
- Select GitHub as the source provider
- Select target GitHub repository
- Select target branch
In the step 3:
- Select AWS CodeBuild
- Select create project In the create build project popup window
- Enter a project name
- Select Ubuntu as the Operating system
- Select "Standard"
- Select "image:2.0"
- select New service role and role name
- go to IAM console and add a
PutObject
permission to the S3 bucket as specified in the buildspec.yml
{
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::bucketname/*"
],
"Action": [
"s3:PutObject"
]
}
In the step 4:
- Select AWS Cloudformation
- Under the action mode, select “create or update a stack”
- Enter a stack name
- Under the Artifact name, select “BuildArctifact”. Enter “packaged-template.yml” in the File name
- Under the Capabilities, select “CAPABILITY_AUTO_EXPAND” and “CAPABILITY_IAM”
- Select a role name. (Note. You need to create a role with the necessary permissions)
- Under the advanced, supply the Parameter Override
{"APPIMGROOTPATH":"https://img.cloud.lib.vt.edu/iawa/","BibliographicCitation":"Researchers wishing to cite this collection should include the following information: - Special Collections, Virginia Polytechnic Institute and State University, Blacksburg, Va.","CollectionCategory":"IAWA","DYNOCollectionTABLE":"Collection-xxxxxx","DYNOArchiveTABLE":"Archive-yyyyyy","NOIDNAA":"53696","NOIDScheme":"ark:/","NOIDTemplate":"eeddeede","REGION":"us-east-1","RightsHolder":"Special Collections, University Libraries, Virginia Tech","RightsStatement":"Permission to publish material from the must be obtained from University Libraries Special Collections, Virginia Tech.","S3BucketName":"iawa-s3csv","LambdaLayerParameter":"arn:aws:lambda:us-east-1:xxxxxxxxx:layer:iawa-layer:1"}
That's it, click the next button and start the codepipeline. If everything works, it should show succeed in every stages.
💖 💪 🙅 🚩
Yinlin Chen
Posted on April 3, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.