Some tests for developing Lambda functions
Follow the getting started guide.
- Create user
- Create access key
- Download CLI
brew install awscli
- Configure AWS CLI
aws configure
(enter access/secret key, region and 'json' as output format) - Pull local lambda java docker environment.
docker pull lambci/lambda:java8
github
Run a docker container and mount the code through as a volume:
docker run --rm -v "$PWD"/task:/var/task lambci/lambda:nodejs6.10
Simple String-length count handler
Make package
mvn package
Run a docker container with parameters:
docker run --rm -v "$PWD/target/classes":/var/task lambci/lambda:java8 com.shaunscaling.lambdatest.StringHandler::countHandler '"GAH"'
Use SAM to test locally.
In the correct directory, start SAM
cd products && sam local start-api
Execute various requests
curl http://localhost:3000/products
curl -XPOST http://localhost:3000/products
curl -XDELETE http://localhost:3000/products/1
curl -XPUT http://localhost:3000/products/1
curl -XPATCH http://localhost:3000/products
Java - with S3 Event
Requires the protobuf-test artifact to be installed locally.
Uses ./template.yaml
to define function / behaviour (the SAM spec)
mvn package
sam local generate-event s3 --bucket testbucket --key testkey > s3event.json
sam local invoke S3Handler -e s3event.json