GithubHelp home page GithubHelp logo

aws-samples / amazon-rds-data-api-demo Goto Github PK

View Code? Open in Web Editor NEW
24.0 3.0 17.0 19 KB

Its an example Lambda app which showcases how to run queries using SDK for Aurora Serverless Data API.

License: MIT No Attribution

Java 52.68% Python 47.32%

amazon-rds-data-api-demo's Introduction

Amazon RDS Data API Demo

Its an example Lambda function which showcases how to run queries using SDK for Aurora Serverless Data API.

The Lambda app runs a SQL INSERT and SELECT using the Data API.

https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html

Requirements

This package requires gradle for building it.

gradle build

This will generate a zip file under build/distributions that can be uploaded to AWS Lambda for running it.

Configuration

Running this Lambda function requires the following setup:

  1. Setup Amazon Pinpoint Application and provision and Long Code for sending/receiving SMS.

  2. Aurora Mysql Serverless database with Data API enabled.

  3. A Secret store which contains username/password for the database.

  4. Further the demo depends on the following table in the database to be created:

    CREATE DATABASE Demo;

    CREATE TABLE Demo.Cities(City varchar(255));

How to use the Demo Lambda Application

  1. Create a new Lambda function with name CityNameHandler, and Handler "CityVoteHandler::handleRequest"

  2. Modify CityVoteHandler.java to include your database ARN and Secret store ARN.

  3. Modify SMSSender.java to include your Amazon Pinpoint Application ID and Long Code

  4. Run 'gradle build' and upload the zip file created to the lambda function

  5. Setup AmazonPinpoint to invoke Lambda which it receives a SMS. Example Setup:

  6. Modify the Lambda IAM role to add following permissions:

Permissions to call ExecuteSql API for the Aurora Serverless database.

{
    "Effect": "Allow",
    "Action": "rds-data:ExecuteSql",
    "Resource": "ARN of Aurora MySQL Serverless Database"
}

Permissions to call AmazonPinpoint to send SMS

{
    "Effect": "Allow",
    "Action": "mobiletargeting:SendMessages",
    "Resource": "arn:aws:mobiletargeting:region:account-id:apps/project-id/messages"
}

Permissions to the secret store with the database username/password

{
    "Effect": "Allow",
    "Action": "secretsmanager:GetSecretValue",
    "Resource": "ARN of Secret which contains the username/password"
}

Running Demo Lambda

Just send a SMS with city name, e.g. Seattle, to the Long Code that you provisioned, and you should get a reply back. Also the city name will be stored in your Aurora database by the Lambda function using Data API. The number of people from same city will be counted using Select statement, using Data API as well.

License Summary

This sample code is made available under a modified MIT license. See the LICENSE file.

amazon-rds-data-api-demo's People

Contributors

matiosb avatar sidhujagdeep avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

amazon-rds-data-api-demo's Issues

Init of SQL client should be in the init of the funciton.

ttps://github.com/aws-samples/amazon-rds-data-api-demo/blob/1d5e3d0277f92d06e6460afd1b6c0b3be10d9234/src/main/python/lambda_function_postgres.py#L58

The creation of the RDS client should have been before the function handler, during the initialisation of the function so it shall be reused across function invocations to avoid issues related to a large number of open connections to the DB.

Lambda Ref: https://docs.aws.amazon.com/lambda/latest/operatorguide/static-initialization.html

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.