python-lambda-template
python-lambda-template copied to clipboard
Python Lambda SAM + SAM Local Project
Python Lambda Template: A sample repository that develops Lambda Function
Initialization
cd python-lambda-template
python - m venv.
source bin / activate.fish
pip install -r requirements.txt
Intellij Settings
- Project Structures> Python> Create your SDK with your Python
- Add SDK classpath:
/path/to/python/lib/python3.6 - Project Structures> Modules> Attatch src and test directory as
SourcesandTests - install requirements.txt on Intellij
Unit Test
Using pytest.
make test-unit
Deploy
Using AWS Serverless Application Model (AWS SAM).
Your task:
- Edit
Makevarsfor your environment. - Create AWS SAM template in
templates/directory. - Create Lambda handler in
src/functions/handlers/directory.
The name of the following ${resource_name} has to be matched:
templates/template_${resource_name}.yamlsrc/functions/handlers/${resource_name}/example_handler.py- Make task:
make deploy-${resource_name}
Before deploy, you should set your AccessKey and Secret for your AWS account. Deploy example:
make deploy-heroes env=test account_id=9999999999999
CI / CD on AWS CodeBuild
Create S3 bucket for deoloy.
aws s3 mb s3://hero-lambda-deploy --profile your-profile
Create CodeBuild project and build.
- Your CloudFormation stack will be created.
- Your Lambda Function will be deployed.