GithubHelp home page GithubHelp logo

optionalg / cloudformation-template-for-lambda-backed-api-gateway-with-vpc-and-redis-cluster Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jthomerson/cloudformation-template-for-lambda-backed-api-gateway-with-vpc-and-redis-cluster

0.0 2.0 0.0 10 KB

License: MIT License

JavaScript 100.00%

cloudformation-template-for-lambda-backed-api-gateway-with-vpc-and-redis-cluster's Introduction

CloudFormation Example for API Gateway With Lambda and a Redis Cluster in Your VPC

What?

This template tries to demonstrate a complete microservice that uses AWS services to create a simple serverless API. It uses CloudFormation to create the following and relate all of them to one another as needed:

  • API Gateway
    • API Resource (one)
    • API Methods (GET / POST)
  • Lambda Function
    • This is what implements the logic for the service, and the code for the function is also part of this repo.
  • Redis ElastiCache Cluster
    • Configured to be used by the Lambda function.
    • This runs in your VPC (because it's accessed via a port on your network, AWS requires this)
  • IAM Roles and Policies
    • So that the API can invoke the function and the function has access to necessary resources.

Why?

Because it can be really tough getting all of this set up on your own. There are a number of examples of individual pieces, but I couldn't find examples of how to wire all of them together.

The goal of this repo is that you can have a single repo that contains the Lambda code for the service, as well as the configuration for provisioning the service. The hope is that you could add automated unit testing, and if that passed, the same repo could build your dev environment, potentially run integration tests, and then either automatically or manually deploy the API. Automating all of this will greatly simplify things if your desire is to build self-contained serverless microservices.

How to Use It

  1. Install custom resources for API creation via CloudFront
    • We use Carl Nordenfelt's great custom resources for making the API resources in AWS CloudFormation since CFN doesn't actually support them natively yet. To get started with it, please install them as described in his documentation: https://apigatewaycloudformation.bynordenfelt.com/. I built this using the latest version at the time: 1.5.0 (2016-04-10).
  2. Copy cloudformation/sample-params.json to cloudformation/api-params.json.
  3. Edit cloudformation/api-params.json to fill in your own values.
  4. Run the following command:
aws cloudformation create-stack --stack-name <YOURSTACKNAME-CAN-BE-ANYTHING> \
    --template-body file://./cloudformation/complete-api.template \
    --parameters=file://./cloudformation/api-params.json \
    --capabilities CAPABILITY_IAM

If you want to monitor the status of your stack creation on the CLI, you can use this command:

aws cloudformation describe-stacks --query='Stacks[*].{ Name: StackName, Status: StackStatus }'

License

This software is released under the MIT license. See the license file for more details.

Feel free to take the template and modify it for your own use.

Contributing

At this point I don't have my normal jshint, jscs, Travis CI stack integrated in this repo. I also don't have unit testing - something I hope to add in the future. So, I don't have a way you can automatically validate your contributions. That said, if you want to contribute, please submit a pull request, but only after doing the following:

  1. Make sure your code follows the coding standards that are in the file(s) you are editing (e.g. three space indentation, never a tab, never trailing whitespace).
  2. (Obviously) Run your code and make sure that you can actually build a working stack with it.

cloudformation-template-for-lambda-backed-api-gateway-with-vpc-and-redis-cluster's People

Contributors

jthomerson 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.