Coder Social home page Coder Social logo

aws-cdk-serverlessbackend's Introduction

AWS CDK for Serverless Backend in Python

python 3.5 3.6 3.7 AWS CDK

This project uses the AWS CDK (Cloud Development Kit), an Amazon Toolkit to define IaC (Infrastructure as Code) using Python. AWS CDK converts the implemented code to CloudFormation (which uses an AWS syntax to describe and provision all the infrastructure resources in AWS).

Features

In this project we have implemented an AWS CDK app to deploy a simple AWS serverless infrastructure. It deploys the following AWS services:

  • Lambda - a sample lambda
  • Cloudwatch Rule Trigger - which triggers the lambda based on cron or rule defined
  • RDS Mysql Instance - Basic free tier Mysql RDS
  • API Gateway (with cors support) - which calls the lambda
  • S3

The goal is to define a simple infrastructure that we can use in all the projects as well as introduce specific aspects (which might not necessarily be needed in this project but might be useful in other more complex projects or with a specific purpose).

The Resources can be easily adapted to a non-serverless architecture also.

Usage

To manually create a virtualenv on MacOS, Linux or Windows:

$ python -m venv .env

After the init process completes and the virtualenv is created, you can use the following step to activate your virtualenv.

$ source .env/bin/activate

If you are a Windows platform, you would activate the virtualenv like this:

% .env\Scripts\activate.bat

Once the virtualenv is activated, you can install the required dependencies.

$ pip install -r requirements.txt

At this point you can now synthesize the CloudFormation template for this code.

$ cdk synth

After running the above command, you can find the CloudFormation Template in the cdk.out directory, validate and deploy using

$ cdk deploy

Understand the Structure

  • app.py: Entry point to the CDK App.
  • cdk.json: A configuration file that defines how to execute the application.
  • cdk.out/*: When cdk synth is executed, CloudFormation templates are placed under this directory. These files are used for deploying the insfrastrure with cdk deploy
  • serverlessbackend/libs: Library files, i.e. custom resources. The reason why we separated the resource classes from the ServerlessBackend Stack is that the custom resource classes can be enforced with organizational or the general best practices and the users can use them inside the stack as is.
  • serverlessbackend/config.properties: List of config values provided.
  • serverlessbackend/serverless_backend.py: This is where the CloudFormation template gets created.

Other Useful commands

  • cdk ls list all stacks in the app
  • cdk synth emits the synthesized CloudFormation template
  • cdk deploy deploy this stack to your default AWS account/region
  • cdk diff compare deployed stack with current state
  • cdk docs open CDK documentation

Still, there is a lot of room for improvement. Hope this will be useful.

Happy Learning!

aws-cdk-serverlessbackend's People

Contributors

rajkumarbestha avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.