Git Product home page Git Product logo

dove's Introduction

chalice-lambda-dynamodb-example

This is an example of using Python and Chalice to run an AWS Lambda function behind an AWS API gateway. The Lambda function has access to write to a DynamoDB table.

architecture

Setup

  1. Install Python 3.6.X: https://www.python.org/downloads/release/python-369/
  • Chalice supports all versions of Python that AWS Lambda supports (2.7 and 3.6).
  1. Install the AWS CLI: https://aws.amazon.com/cli/
  2. Configure the AWS CLI with an IAM user that has programmatic access enabled by running aws configure. The user should have permissions to create API Gateways, IAM roles, and Lambda functions in the region you have configured.
  3. Install Chalice and Boto3: python -m pip install chalice && python -m pip install boto3
  • Depending on your operating system and how you installed Python 3, you may need to do some additional work to set up pip. (e.g. on CentOS yum install -y python-pip).
  1. Run chalice deploy
  • Again, depending on how you installed Python, you may need to add the Python Scripts folder to your PATH environment variable. You can also try python -m chalice
  1. Open the IAM service in the AWS Console and go to Roles. Attach the AmazonDynamoDBFullAccess policy to the lambda-dyanmodb-example-dev role created by Chalice.
  2. Create a DynamoDB table using CloudFormation by running make table or aws cloudformation deploy --template-file resources.json --stack-name devices-table
  3. Get the name of the table by running make table-info or aws dynamodb describe-table --table-name $(aws cloudformation describe-stacks --query "Stacks[0].Outputs[?OutputKey=='DevicesTableName'].OutputValue" --output text)
  4. Replace the table_name variable in app.py with the output from the previous step.
  5. Invoke the function using cURL or your preferred http client: curl -X PUT https://<YOUR_API_GATEWAY_ID>.execute-api.<YOUR_REGION>.amazonaws.com/api/insert -H "Content-Type:application/json" -d @event.json

For more information on how to configure the deployment (Lambda functions's compute specifications, tagging, roles, environment variables) see https://chalice.readthedocs.io/en/latest/topics/configfile.html.

Have a question or need some help? Open an Issue.

dove's People

Contributors

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