Code Monkey home page Code Monkey logo

ontra's Introduction

ontra

How to

Hi! This repo contains all you need to deploy a small api endpoint to AWS that responds to HTTP GET requests and returns a JSON payload in the form {"The current epoch time": <EPOCH_TIME>} where <EPOCH_TIME> is an integer representing the current epoch time in seconds.

Requirements

To get started, make sure you have the following things installed locally

Deploy

# start by exporting your AWS creds for use by terraform and awscli
# make sure to replace with your creds
export AWS_SECRET_ACCESS_KEY="mysecretkey"
export AWS_ACCESS_KEY_ID="mysecretid"

# assuming you've downloaded this repo locally, and are in the directory
# let's build our infra!
make build

# let's test our infra!
make get

# now that we're done, let's destroy everything
make destroy

How things work

At a high level, we leverage an Amazon API Gateway to act as the front door to our service hosted on AWS Lambda. Our container image is hosted in Amazon Elastic Container Registry.

make build

  1. A targeted terraform apply to creates our ECR registry to host our container image
  2. It then authenticates docker with ECR, so you can push a local image to it
  3. A docker build is kicked off that builds an arm64 image, and pushed to ECR
    • ECR doesn't support multiarch images, and so we build specifically for arm64, so that architecture differences between build machines don't break this step
    • The entire application is contained in app.py which simply returns a formatted json response with the time
    • The Containerfile is a multistage build that creates a distroless small footprint image that
    • The created image is then pushed to ECR
  4. A complete terraform apply which creates the following
    • An REST API gateway that has an /time path that accepts GET requests
    • A lambda that runs our image from ECR
    • A API Gateway integration to link up the gateway to the lambda function
    • Permissions to connect ECR + Lambda, Cloudwatch + Lambda (for monitoring), Lambda + API Gateway

Make get

This just runs a curl against our service

Make destroy

  1. This starts by deleting images in the ECR gateway
  2. Runs terraform destroy to delete all our resources

Developing

Testing locally

You can test locally, by spinning up a docker image.

$ docker run -p 9000:8080  ontra
30 Sep 2023 00:43:17,508 [INFO] (rapid) exec '/usr/bin/python' (cwd=/var/task, handler=app.handler)

# in another shell
$ curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'                           [17:42:57]
{"statusCode": 200, "body": "{\"The current epoch time\": 1696034577}", "headers": {"Content-Type": "application/json"}}%

ontra's People

Contributors

joshuajcoronado avatar

Watchers

 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.