Giter VIP home page Giter VIP logo

special-responder-example's Introduction

Special Responder

A fancy little thingamajiger to launch a API Gateway / Lambda function in AWS.

arch

Introduction

This is a tool that can be used to build, test, and deploy a Lambda function behind an API Gateway in Amazon Web Services that returns a specific response. In this case:

{
  "message": "Automation for the People",
  "timestamp": "<current_epoch>"
}

Getting Started

Requirements

This tool requires the following pre-requisites:

  1. Linux, Mac, or Compatible bash-enabled OS
  2. Docker
  3. Docker-Compose
  4. Git CLI
  5. An AWS Account with the credential chain initialized.
    1. for more info, see this: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html
  6. An S3 Bucket
    1. Doesn't have to already exist but the name specified must be unique.
    2. This tool will create the bucket for you if it doesn't already exist.

The Easy Way

If you feel like skipping the below steps and doing it the easy way, feel free to run this:

# EXAMPLE: ./up.sh my_bucket v0.0.5
./up.sh <my_s3_bucket_name> <my_version>

To destroy and cleanup your environment, simply run:

./down.sh

The Hard Way ( A.K.A = But I want to know how it works! )

Build fixtures

This tool uses docker-compose to make some of the standup orchestration simpler and easier.
To get started, clone this repo and run a compose build, like this:

mkdir special-responder && cd special-responder
git clone https://github.com/stelligent/miniproject-LUCAS-MICHAEL.git .
docker-compose build

Run Tests

Like my grandma used to say: If you're not unit testing, it's broken.

In order to run a full suite of unit tests, you can run the following:

docker-compose run test

This uses python's built in "unittest" library to run a few basic tests, including:

  • Testing the instantiation of the class.
  • Testing the logic that allows the injection of a custom message.
  • Asserting that the timestamp is epoch to the second without milliseconds.

Inital Setup

As stated in the pre-requisites, an S3 bucket is needed to store the codebase. Let's copy the env.sh.template to env.sh and make some changes.

cp env.sh.template env.sh

Put the name of the S3 bucket in "env.sh" at the line with the following:

export S3_BUCKET_NAME="<bucket_name>"
# EXAMPLE: export S3_BUCKET_NAME="my-bucket"

This will actually create the bucket if it doesn't exist, but its better to make sure that the bucket exists first.

Then you can set the version number.

export TF_VAR_function_version="<version>"
# EXAMPLE: export TF_VAR_function_version="v0.0.1"

Once that is complete you can source the env to load your AWS credentials to the environment so terraform can access them through docker-compose's environment variables integration.

source env.sh

Upload your code

There is a nice little fixture to simplify uploading the lambda code to s3.

docker-compose run upload

You can optionally supply the version number for this deployment. Just be sure to update the version number either in "env.sh" or by statically writing it into "deployment/main.tf".

docker-compose run upload v0.0.1

Deploy your stack to AWS

This tool uses terraform to provision the necessary AWS resources to run the stack. This includes the following resources:

  • API Gateway API, Resources, Stages, etc
  • AWS Lambda Function
  • IAM Roles and Polices for Execution and Invocation

First, change directory to ./deployment/ and edit the main.tf there as needed. Follow the comments and directions in the file. This main.tf is the root file that terraform will reference in the next step.

docker-compose run deploy

Terraform should return an output for each "module" stanza in "deployment/main.tf". Each of these outputs, should the odds be ever in our favor, will be a functional endpoint returning the desired output.

OPTIONALLY: Run any terraform command

You can also optionally run ANY terraform command with docker-compose like so:

docker-compose run terraform destroy

UML for Deployment logic

uml

In Conclusion

I hope you had fun reviewing my fun little thingamajiger. Feel free to drop any questions or improvements as issues to the repo!

special-responder-example's People

Contributors

nubbthedestroyer avatar trishallsopp avatar

Watchers

James Cloos avatar Praveen Kumar Kolla 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.