Deploy a Lambda function triggered by S3 event using CodePipeline

yinlinchen

Yinlin Chen

Posted on April 3, 2020

Deploy a Lambda function triggered by S3 event using CodePipeline

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:

  1. Enter a pipeline name
  2. Under service role, select new service role and enter a role name, click Next button. Alt Text

In the Step 2:

  1. Select GitHub as the source provider
  2. Select target GitHub repository
  3. Select target branch Alt Text

In the step 3:

  1. Select AWS CodeBuild
  2. Select create project In the create build project popup window
  3. Enter a project name
  4. Select Ubuntu as the Operating system
  5. Select "Standard"
  6. Select "image:2.0"
  7. select New service role and role name Alt Text
  8. 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:

  1. Select AWS Cloudformation
  2. Under the action mode, select “create or update a stack”
  3. Enter a stack name
  4. Under the Artifact name, select “BuildArctifact”. Enter “packaged-template.yml” in the File name
  5. Under the Capabilities, select “CAPABILITY_AUTO_EXPAND” and “CAPABILITY_IAM”
  6. Select a role name. (Note. You need to create a role with the necessary permissions)
  7. 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"}

Alt Text

That's it, click the next button and start the codepipeline. If everything works, it should show succeed in every stages.
Alt Text

💖 💪 🙅 🚩
yinlinchen
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.

Related