This project helps a user complete the 1p saving challenges:
This project has 2 sections:
- Backend Code
- Infrastructure as Code (CDK)
The logic code is written in python and stored in ./app
-
amount/until/next_payday
This lambda calculates how many days till next payday then returns the amount that needs to be saved between now and then
This involves multiplying the number days by the daily saving amount (3.66)
The file isapp/src/amount/until/next_payday/app.py
The entrypoint islambda_handler
The CDK is written in TypeScript
This project has been built using AWS CDK version 1.61.1
The cdk cli tool requires aws credentials.
I use an AWS educate account more info
But any account that has these credentials: aws_access_key_id; aws_secret_access_key; aws_session_token; will do
If you have not used CDK in your AWS account before please run cdk bootstrap
before starting
The CDK includes 2 components
- API Gateway
- Lambda Function
The Serverless function allows us to call our Scripts
penny-calc-amount-until-next-payday-lambda
This lambda runs theamount/until/next_payday
script
The API Gateway provides access to the backend through Rest API calls.
/amount/until/next-payday
This endpoint is a GET method endpoint
Using an AWS_PROXY lamdba integration
This endpoint links up to the lambda namedpenny-calc-amount-until-next-payday-lambda
It is reccommended to install the packages required
run these commands to get started
PIPENV_VENV_IN_PROJECT=1 pipenv install --dev
PIPENV_VENV_IN_PROJECT=1 pipenv install
npm install
export $(cat .env | xargs)
Every time you change values in /.env
run export $(cat .env | xargs)
A number of the commands rely on the cdk cli and so please have a valid session/token from AWS
-
npm run build
Runs the following commandsbuild-python
build-cdk
-
npm run build-python
This command builds the python code with the packages installed into the build directory -
npm run build-cdk
Runs the following commandsclean-cdk
cdk-synth
-
npm run cdk-synth
This command builds a cloudformation template from the CDK stack
Prequisite:build-python
-
npm run cdk-diff
This command shows the difference between the latest template and the previous one -
npm run deploy
This command deploys the cloudformation stack
Prequisite:ckd-synth
-
npm run deploy-ci
Follows the same behaviour ascdk-deploy
but does not ask for confirmation
Prequisite:ckd-synth
-
npm run test-cdk
Tests the CDK stack Refer to the Testing Section -
npm run test-python
Tests the Python scripts Refer to the Testing Section -
npm run tsc
Runs the typescript complier -
npm run clean
Runs the following commandsclean-tests
clean-build
clean-cdk
-
npm run clean-tests
Removes temporary test files -
npm run clean-build
Removes temporary build files -
npm run clean-cdk
Removes temporary cdk files -
npm run run-lambda-local
Runs the lambda locally
There are tests for both the cdk stack and backend code
- CDK tests
npm run test-cdk
Written in TypeScript and using jest as the test runner - Python tests
npm run test-python
Written in python and using pytest as the test runner
This is a blank project for TypeScript development with CDK.
The cdk.json
file tells the CDK Toolkit how to execute your app.
npm run build
compile typescript to jsnpm run watch
watch for changes and compilenpm run test
perform the jest unit testscdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk synth
emits the synthesized CloudFormation template