Skip to content

eoinkane/penny-calc-backend

Repository files navigation

Penny-Calc Backend

This project helps a user complete the 1p saving challenges:

This project has 2 sections:

  • Backend Code
  • Infrastructure as Code (CDK)

Backend Code

The logic code is written in python and stored in ./app

List of Scripts

  • 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 is app/src/amount/until/next_payday/app.py
    The entrypoint is lambda_handler

Infrastructure as Code (CDK)

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

Components

The CDK includes 2 components

  • API Gateway
  • Lambda Function

Lambda Function

The Serverless function allows us to call our Scripts

List of Lambdas

  • penny-calc-amount-until-next-payday-lambda
    This lambda runs the amount/until/next_payday script

API Gateway

The API Gateway provides access to the backend through Rest API calls.

Endpoints

  • /amount/until/next-payday This endpoint is a GET method endpoint
    Using an AWS_PROXY lamdba integration
    This endpoint links up to the lambda named penny-calc-amount-until-next-payday-lambda

Comands

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

List of Comands

  • npm run build Runs the following commands

    • build-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 commands

    • clean-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 as cdk-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 commands

    • clean-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

Testing

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

Welcome to your CDK TypeScript project

This is a blank project for TypeScript development with CDK.

The cdk.json file tells the CDK Toolkit how to execute your app.

Useful commands

  • npm run build compile typescript to js
  • npm run watch watch for changes and compile
  • npm run test perform the jest unit tests
  • cdk deploy deploy this stack to your default AWS account/region
  • cdk diff compare deployed stack with current state
  • cdk synth emits the synthesized CloudFormation template

About

This project helps a user complete the 1p saving challenges:

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published