- install pre-commit
- configure pre-commit:
pre-commit install
- install required tools
Write code according to I&A module standards
Do not manually update README.md. terraform-docs
is used to generate README files. For any instructions an content, please update .header.md then simply run terraform-docs ./
or allow the pre-commit
to do so.
This implementation of AWS Lambda uses docker containers to run the code. The lambda function consists of a function name and is associated to a container image. The container image is stored in AWS ECR.
There are two files to update the lambda function:
- The
Dockerfile
contains the instructions to build the container image. - The
requirements.txt
file contains the list of Python packages that are installed in the container image.
All other files are used to test the Lambda function locally and are not required for cloud deployments with AWS.
The Lambda function code is located in the app.py
file. The lambda_handler
function is the entry point for the Lambda function.
From the root directory, run the following command to build the Docker image:
docker build -t 860100747351.dkr.ecr.us-east-1.amazonaws.com/python:3.9 . --platform=linux/amd64 --no-cache
Note: The
--platform=linux/amd64
flag is required to build the Docker image for thepython:3.9
image when using environments with other architecture types, such as MacOSX with M1 (ARM) processors. The--no-cache
flag is used to force a rebuild of the image.
This section explains how to test your AWS Lambda function locally using the AWS Serverless Application Model (SAM) CLI and Docker.
From the tests/lambda_function
directory, run the following commands to build and invoke the Lambda function locally:
sam build --use-container
sam local invoke ExecuteCodeFunction -e event.json
The sam local invoke ...
command will run your Lambda function in a Docker container and use the event.json
file as the input event.
If the function ran successfully, you should see the following output:
{"statusCode": 200, "body": "{\"result\": {\"a\": 5, \"b\": 20}}"}
From the root directory, run the following command to test the Lambda function with Boto3. Ensure that the ARN
value is exported with the LAMBDA_FUNCTION_ARN
environment variable before executing the test:
# example for development environment lambda function
export LAMBDA_FUNCTION_ARN=arn:aws:lambda:us-east-1:860100747351:function:app-dev-docker-lambda_handler
python test_lambda_with_arn.py
This should output a result similar to the following:
{'statusCode': 200, 'body': '{"result": {"a": 5, "b": 20}}'}
Please include tests to validate your examples/<> root modules, at a minimum. This can be accomplished with usually only slight modifications to the boilerplate test provided in this template
-
Install
golang (for macos you can use
brew
) -
Change directory into the test folder.
cd tests
-
Initialize your test
go mod init github.com/[github_org]/[repo_name]
For example:
go mod init github.com/illumidesk/illumidesk-cloud
-
Run tidy
git mod tidy
-
Install Terratest
go get github.com/gruntwork-io/terratest/modules/terraform
-
Run test (You can have multiple test files).
-
Run all tests
go test
-
Run a specific test with a timeout
go test -run TestExamplesBasic -timeout 45m
-
The IllumiDesk team uses GitHub Actions to perform continuous integration (CI) within the organization. Our CI uses the a repo's .pre-commit-config.yaml
file as well as some other checks.
Name | Version |
---|---|
terraform | >= 1.0.7 |
aws | >= 4.0.0, < 5.0.0 |
awscc | >= 0.24.0 |