This repo presents one approach to use SAM Local in a real-world scenario. It provides an example of how to local develop an AWS Lambda function, using the same build steps locally and in the CI pipeline.
Using AWS Lambda, I want to send notifications to a 3rd party API using SMS. The AWS Lambda is behind an AWS API Gateway, and the requests and responses are being proxy.
The 3rd party API can return the following responses:
- Invalid credentials (
Unauthorized (401)
) - If the client does not set the proper credentials using the Authorization HTTP header, the API returns anUnauthorized
HTTP Status Code - Insufficient Credits (
Forbidden (403)
) - If the user account doesn't have credits to use the resources, the API returns aForbidden
HTTP Status Code - Ok (
OK (200)
) - If the API sends the SMS, it returns anOk
HTTP Status Code
The AWS Lambda function is implemented using .NET Core 2.0, and is using the APIGatewayProxyRequest
and APIGatewayProxyResponse
to be able to communicate with AWS API Gateway.
To be able to local test the AWS Lambda implementation, the project uses SAM Local to bootstrap all the necessary components to test it. The SAM Local is instrumented using the template.yml
located at ./build
folder.
Given the 3rd party API doesn't provide a sandbox mode for the acceptance tests, a Testing API was created where it is possible to replicate the behavior of the real API. SAM Local uses Docker containers, therefore the Testing API is implemented using the same technology.
The Acceptance Tests are based on the expected behavior of the API (BDD FTW), where it uses a Given/When/Then
declarative instructions to specify the steps for the tests.
You can follow the download instructions or use your preferred package manager.
You can follow the download instructions or use your preferred package manager.
You can follow the download instructions or use your preferred package manager.
It uses Cake to build and run the tests in a transparent way in all supported platforms.
Using a Powershell terminal, on the root folder of the project:
./build.ps1 --target=Test-Local
Using a Terminal, on the root folder of the project:
sh ./build.sh --target=Test-Local
At the moment, there are issues with the Docker Network on Windows. We are investigating a solution to it. Please stay tuned!