Giter VIP home page Giter VIP logo

aws-lambda-ganache's Introduction

AWS Lambda Function with Ganache

Reference: https://gitcoin.co/issue/blockgeeks/BountyAnyERC20/3/100023523

Goal

  • Create an AWS Lambda Function (see https://console.aws.amazon.com/lambda) that generates a Node.js app and deploys any contract on Ganache and uses web3 or ethers to get any data from that contract.

  • Call the AWS Lambda Function and run the code in response to a HTTP request using Amazon API Gateway or using API calls with the AWS SDK

  • Note:

Setup AWS CLI

https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html

cd ~/Downloads
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg" && \
  sudo installer -pkg AWSCLIV2.pkg -target && \
  aws --version

Setup AWS Credentials

Create new Access Key from https://console.aws.amazon.com/billing/home?#/account then click username and "My Security Credentials", then "Access keys (access key ID and secret access key)"

Set Access Keys

aws configure

Available regions to use include (e.g. ap-southeast-2): https://docs.aws.amazon.com/general/latest/gr/rande.html

Output formats include (e.g. json): https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-output.html

Add AWS Account ID to .env file

Obtain AWS Account ID from https://console.aws.amazon.com/billing/home?#/account then click username and "My Security Credentials", then "Account Identifiers"

Alternatively run aws sts get-caller-identity

Create Execution Role

  • Create Execution Role and add the AWSLambdaBasicExecutionRole policy since it has the permissions that the function needs to write logs to CloudWatch Logs.
aws iam create-role --role-name lambda-ex --assume-role-policy-document file://trust-policy.json
aws iam attach-role-policy --role-name lambda-ex --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole

Create Deployment Package of AWS Lambda Function with Dependencies

Check that Node.js version in local environment matches the Node.js version of the AWS Lambda function.

Switch to Node.js v10.x

Install libraries into the node_modules/ directory

npm install;

Create zip file containing contents of project folder

zip -r my-function.zip .
./scripts/create-function.sh

Run AWS Lambda Function Locally

node index.js

View Logs

./scripts/get-logs-all.sh
./scripts/get-logs-last5.sh

References

https://docs.aws.amazon.com/lambda/latest/dg/welcome.html https://docs.aws.amazon.com/lambda/latest/dg/getting-started.html https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-awscli.html https://docs.aws.amazon.com/lambda/latest/dg/lambda-nodejs.html https://docs.aws.amazon.com/lambda/latest/dg/nodejs-package.html

aws-lambda-ganache's People

Contributors

ltfschoen avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

thebkr7

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.