Skip to content
John Fereira edited this page Apr 5, 2022 · 1 revision

Lambda Demo

Contents

The project source includes function code and supporting resources:

  • src/main - A Java function.
  • template.yml - An AWS CloudFormation template that creates an application.
  • build.gradle - A Gradle build file.
  • pom.xml - A Maven build file.
  • 1-create-bucket.sh, 2-deploy.sh, etc. - Shell scripts that use the AWS CLI to deploy and manage the application.

Use the following instructions to deploy the sample application.

Requirements

Setup

Download or clone this repository.

$ git clone https://github.com/fereira/javadev    
$ cd javadev/LambdaDemo

Copy the awsenv-example.sh script to awsenv.sh to set variables for the AWS_ACCESS_KEY and AWS_SECRET_ACCESS_KEY

To create a new bucket for deployment artifacts, run 1-create-bucket.sh.

$ ./1-create-bucket.sh
make_bucket: aws-lambda-demo-app-a5e491dbb5b22e0d

Deploy

To build and deploy, run the 2-deploy.sh script. This will run maven to compile the code, then will use aws cloudformation and the template.yml file to copy the resources to a stack.

To deploy the application, run 2-deploy.sh.

$ ./2-deploy.sh 

This script uses AWS CloudFormation to deploy the Lambda functions and an IAM role. If the AWS CloudFormation stack that contains the resources already exists, the script updates it with any changes to the template or function code.

Test

To test, execute the s3-invoke.sh script

s3-java$ ./3-invoke.sh
{
    "StatusCode": 200,
    "ExecutedVersion": "$LATEST"
}

The function will execute 3 times

Cleanup

To delete the application, run 6-cleanup.sh.

$ ./4-cleanup.sh
Clone this wiki locally