Skip to content

Latest commit

 

History

History

apigw-lambda-snapstart-terraform

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Amazon API Gateway, AWS Lambda and Amazon DynamoDB with Lambda SnapStart for Java deployed with Terraform

Requirements

Deployment Instructions

  1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
    git clone https://github.com/aws-samples/serverless-patterns
    
  2. Change directory to the pattern directory:
    cd apigw-lambda-snapstart-terraform
    
  3. Build the function:
    cd UnicornStockLambda
    mvn package
    cd ..
    
  4. From the command line, initialize terraform to download and install the providers defined in the configuration:
    terraform init
    
  5. Deploy the infrastructure
    terraform apply
    
  6. Confirm that it was deployed correctly
    terraform show
    

Testing

To test the Lambda function you can run the artillery load test with the following commands

export API_GW_URL=$(terraform output -raw apigw-url)
artillery run -t $API_GW_URL -v '{ "url": "/transactions" }' UnicornStockLambda/misc/loadtest.yaml

Measuring the results

You can use the following AWS CloudWatch Insights query to measure the duration your SnapStart Lambda function.

filter @type = "REPORT"
  | parse @log /\d+:\/aws\/lambda\/(?<function>.*)/
  | parse @message /Restore Duration: (?<restoreDuration>.*?) ms/
  | stats
count(*) as invocations,
pct(@duration+coalesce(@initDuration,0)+coalesce(restoreDuration,0), 0) as p0,
pct(@duration+coalesce(@initDuration,0)+coalesce(restoreDuration,0), 25) as p25,
pct(@duration+coalesce(@initDuration,0)+coalesce(restoreDuration,0), 50) as p50,
pct(@duration+coalesce(@initDuration,0)+coalesce(restoreDuration,0), 90) as p90,
pct(@duration+coalesce(@initDuration,0)+coalesce(restoreDuration,0), 95) as p95,
pct(@duration+coalesce(@initDuration,0)+coalesce(restoreDuration,0), 99) as p99,
pct(@duration+coalesce(@initDuration,0)+coalesce(restoreDuration,0), 100) as p100
group by function, (ispresent(@initDuration) or ispresent(restoreDuration)) as coldstart
  | sort by coldstart desc

Cleanup

  1. Change directory to the pattern directory:
    cd apigw-lambda-snapstart-terraform
    
  2. Delete all created resources
    terraform destroy
  3. During the prompts:
    • Enter yes
  4. Confirm all created resources has been deleted
    terraform show