Skip to content

Files

Latest commit

 

History

History
 
 

apigw-lambda-snapstart

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

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
    
  3. Build the function
    sam build
    
  4. Deploy the infrastructure
    sam deploy --stack-name unicorn-store --guided
    

Testing

To test the Lambda function you can POST a unicorn JSON payload to the '/unicorns' endpoint.

curl --location --request POST $(aws cloudformation describe-stacks --stack-name unicorn-store --query "Stacks[0].Outputs[?OutputKey=='UnicornEndpoint'].OutputValue" --output text)'/unicorns' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "Something",
"age": "Older",
"type": "Animal",
"size": "Very big"
}' | jq

Measuring the results

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

filter @message like "REPORT"
| filter @message not like "RESTORE_REPORT"
| parse @message /Restore Duration: (?<@restore_duration_ms>[0-9\.]+)/
| parse @message /	Duration: (?<@invoke_duration_ms>[0-9\.]+)/
| fields
  greatest(@restore_duration_ms, 0) as restore_duration_ms,
  greatest(@invoke_duration_ms, 0) as invoke_duration_ms
| fields
  restore_duration_ms + invoke_duration_ms as total_invoke_ms
| stat
  pct(total_invoke_ms, 50) as total_invoke_ms_p50,
  pct(total_invoke_ms, 99) as total_invoke_ms_p99,
  pct(total_invoke_ms, 99.9) as total_invoke_ms_p99.9