Giter VIP home page Giter VIP logo

aws-cdk-sam-chalice's Introduction

Example project for working with AWS CDK, AWS SAM and AWS Chalice

This project shows how AWS CDK, AWS SAM and AWS Chalice can be used together to deliver a service using CDK for building the broader service infrastructure, Chalice as developer-friendly Python serverless microframework and SAM as integration point between the two.

The service is based on Amazon API Gateway and AWS Lambda. The web API provides basic CRUD operations for managing users in a DynamoDB table.

Setting up development environment

See Getting Started With the AWS CDK for additional details and prerequisites

# Install the CDK CLI
npm install -g aws-cdk

# Clone the code
git clone https://github.com/alexpulver/aws-cdk-sam-chalice
cd aws-cdk-sam-chalice

# Create Python virtual environment and install the dependencies
python3 -m venv .venv
source .venv/bin/activate
pip install -r infra/requirements.txt
pip install -r web-api/requirements.txt

Synthesize and deploy development stack

The WebApiDev stack uses your current AWS profile account and credentials.

cd infra
cdk synth
cdk deploy WebApiDev

Example output for cdk deploy ...:

WebApiDev.UsersTableName = WebApiDev-UsersTable9725E9C8-BTQT7EIOV1UC
WebApiDev.APIHandlerArn = arn:aws:lambda:eu-west-1:123456789012:function:WebApiDev-APIHandler-13LVIC507UIAN
WebApiDev.APIHandlerName = WebApiDev-APIHandler-13LVIC507UIAN
WebApiDev.RestAPIId = letbml5594
WebApiDev.EndpointURL = https://letbml5594.execute-api.eu-west-1.amazonaws.com/v1/

Do not forget to delete the stack once done with testing to avoid unexpected charges:

cdk destroy WebApiDev

Testing the web API

Below are examples that show the available resources and how to use them:

curl \
    -H "Content-Type: application/json" \
    -X POST \
    -d '{"username":"john", "email":"[email protected]"}' \
    https://API_ID.execute-api.REGION.amazonaws.com/v1/users

curl \
    -H "Content-Type: application/json" \
    -X GET \
    https://API_ID.execute-api.REGION.amazonaws.com/v1/users/john

curl \
    -H "Content-Type: application/json" \
    -X PUT \
    -d '{"country":"US", "state":"WA"}' \
    https://API_ID.execute-api.REGION.amazonaws.com/v1/users/john

curl \
    -H "Content-Type: application/json" \
    -X DELETE \
    https://API_ID.execute-api.REGION.amazonaws.com/v1/users/john

aws-cdk-sam-chalice's People

Contributors

alexpulver avatar

Watchers

 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.