Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Research]: Running AWS Infrastructure Locally #61

Closed
3 tasks done
AshtonStephens opened this issue Apr 18, 2024 · 5 comments
Closed
3 tasks done

[Research]: Running AWS Infrastructure Locally #61

AshtonStephens opened this issue Apr 18, 2024 · 5 comments
Assignees
Labels
emily API that communicates with Signers to trigger sBTC operations. research consolidating information. test environment The testing envionment used to develop the sBTC-v1 features.

Comments

@AshtonStephens
Copy link
Collaborator

AshtonStephens commented Apr 18, 2024

Completing the issue description and arriving at a conclusion is the deliverable of this issue.

Research - Running AWS Infrastructure Locally

This ticket holds the research relating to running AWS architecture locally and how it impacts sBTC-v1.

1. Summary

It's very feasible to run an API that uses DynamoDB, API Gateway, and AWS Lambda locally without any internet connection. Proof of concept PR: AshtonStephens/simple-aws-website#1

2. Context & Relevance

We need to be able to test all sBTC-v1 infrastructure locally, and while there are a lot of production benefits to using AWS, local environments are a weak point for AWS constructs . We want to determine if we can run AWS Lambda, API Gateway, and DynamoDB for the Deposit API infrastructure locally.

3. Research

3.1 Research Conclusions

We can run all the AWS related infrastructure for the DepositAPI locally and it works very well.

You need to download and run sam which is slightly annoying because doesn't fit neatly into docker compose, but on its own it works seamlessly. In the example I created there's a docker compose file that spins up a local version of DynamoDB as a service and then connects the SAM environment to it via a shared docker network.

I'm sure there are clever ways to make this fit neatly with a docker compose setup, but in my demo the docker compose spins up first, and then the sam command run. This is fine because the build script takes care of everything; we'll want to have clean build scripts for sBTC-v1 as well.

3.1.1 Research Approach

I used an existing AWS project that I know works on AWS, simulated it locally, and checked that its behavior on AWS matched that of my local machine. I've linked the proof of concept above, and here for reference.

3.2 External Resources


Closing Checklist

  • The takeaway from this issue is clearly documented in the description of this ticket.~
  • Everyone necessary has reviewed the resolution and agrees with the takeaways. The proof of concept works.
  • This ticket has or links all the information necessary to familiarize a contributor with the topic and how it was resolved.
@AshtonStephens AshtonStephens added the research consolidating information. label Apr 18, 2024
@AshtonStephens AshtonStephens added this to the Low Level Design milestone Apr 18, 2024
@AshtonStephens AshtonStephens added the emily API that communicates with Signers to trigger sBTC operations. label Apr 18, 2024
@AshtonStephens AshtonStephens self-assigned this Apr 18, 2024
@AshtonStephens AshtonStephens added the test environment The testing envionment used to develop the sBTC-v1 features. label Apr 18, 2024
@AshtonStephens
Copy link
Collaborator Author

So far the lambda is easy to run locally mostly following the setup from the thinkgeek example.

Docker compose at project root:

services:

  lambda:
    build:
      context: lambda
    container_name: lambda
    ports:
      - 9000:8080
    environment:
      MESSAGE_TABLE_NAME: MessageTable-XXXXXXXXXXXX-us-west-2-dev
      AWS_DEFAULT_REGION: us-west-2

    networks:
      - lambda-example
      
    # ... kong part is having issues ... 
      
networks:
  lambda-example:

Dockerfile at path ./lambda/Dockerfile

FROM public.ecr.aws/lambda/python:3.12

# Copy function code
COPY src/entrypoint.py ${LAMBDA_TASK_ROOT}

# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "entrypoint.handler" ]

And then the following curl "works" when you run this in project root, but has errors because there's no DynamoDB container or other services.

    docker compose down lambda
    docker compose build
    docker compose up lambda -d
    curl --silent "http://localhost:9000/2015-03-31/functions/function/invocations" \
            -d '{"resource": "/messages", "httpMethod": "POST", "body": "demo message"}' \
            | jq

The example repository I'm using is AshtonStephens/simple-aws-website (also linked in the issue description) and requires APIGateway, Lambda, and DynamoDB.

@AshtonStephens
Copy link
Collaborator Author

SAM is actually a promising path because it can spin up a full API with an API Gateway specification based on an OpenAPI template. Additionally, the --docker-network for sam calls lets us connect an existing docker network to the api.

@AshtonStephens
Copy link
Collaborator Author

AshtonStephens commented Apr 18, 2024

Got this all working locally:

  • API Gateway
  • AWS Lambda
  • DynamoDB

I'm going to try SecretsManager now. Actually, I'm not because I don't think the DepositAPI needs secrets

@AshtonStephens
Copy link
Collaborator Author

I created a PR for the proof of concept in the demo repository I was using: AshtonStephens/simple-aws-website#1

@netrome
Copy link
Contributor

netrome commented Apr 19, 2024

Nice stuff!

@AshtonStephens AshtonStephens changed the title [Research]: Running AWS Infrastructure Locally with Docker [Research]: Running AWS Infrastructure Locally Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
emily API that communicates with Signers to trigger sBTC operations. research consolidating information. test environment The testing envionment used to develop the sBTC-v1 features.
Projects
Archived in project
Development

No branches or pull requests

2 participants