Skip to content

Latest commit

 

History

History
116 lines (82 loc) · 6 KB

File metadata and controls

116 lines (82 loc) · 6 KB

Getting Started with AWS Configuration

Initial commit from @SourasishBasu.

AWS Infrastructure in use

  • API Gateway can directly communicate with AWS services using their low-level APIs. This includes AWS services such as DynamoDB.
  • DynamoDB is a NoSQL database stores relevant user details along with contact details such as phone numbers in JSON format.
  • DynamoDB Streams captures a time-ordered sequence of item-level modifications in a DynamoDB table [INSERT, MODIFY, DELETE], enabling real-time data processing via pipelines or Lambda functions.
  • EventBridge acts as a pipeline service by providing a streamlined way for events to flow between different components of our applications or other AWS services. It allows you to define event sources, set rules and filters, and seamlessly deliver them to targets for processing.
  • Lambda is a serverless compute service that lets us run code without provisioning or managing servers.
  • SNS is a fully managed topic based publish/subscribe messaging service that will be used to send SMS messages to users.

Setup

Step 1. DynamoDB and Data Streams

Creating the DynamoDB table

  1. Open AWS CloudShell and execute the following commands.

     aws dynamodb create-table \
     --table-name Users \
     --attribute-definitions AttributeName=id,AttributeType=S AttributeName=roll,AttributeType=S \
     --key-schema AttributeName=id,KeyType=HASH  AttributeName=roll,KeyType=RANGE \
     --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \
     --stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES

    This creates a DynamoDB table called Users with id as Partition Key & roll as Sort Key accepting String datatypes. This also enables DynamoDB Streams.

  2. Go to AWS DynamoDB from the AWS Console Homepage and search DynamoDB. Select Tables in the left pane of the DynamoDB page to access your table.

    image

Step 2. AWS Lambda Handler Function

AWS Lambda Configuration

  1. Go to Services > Lambda > Functions > Create function.

  2. Provide a name for the function and select the following configuration

    image

  3. Under the Code Source window copy the contents of the app.py from the repository files.

  4. Go to Configuration > Permissions > Execution Role. Click the role name assigned to the Lambda function which will redirect to the IAM console.

    image

  5. Go to Permission Policies > Add permissions > Attach Policies.

    image

  6. Search and Select Amazon SNS Full Access under Other permissions Policies and click Add permissions.

    image

Step 3. AWS EventBrige Pipeline

Creating the EventBridge Pipeline

  1. Go to Services > Amazon EventBridge > Pipes > Create Pipe.

  2. In the below window, name the pipeline. Under Source, select Source and click on DynamoDB Streams.

  3. Under DynamoDB Stream, select the DynamoDB database from Step 1.

    image

  4. Click on Filtering. From the sample events, select Sample event 1 for DynamoDB Stream.

    image

  5. In the Event pattern, paste the following pattern.

    {
      "dynamodb": {
        "NewImage": {
          "phone": {
            "S": [{
              "prefix": "+91"
            }]
          }
        }
      }
    }

    The EventBridge Pipeline will trigger Lambda function only if new records from DynamoDB have a prefix +91 in the phone column. This filters user records having the country code [+91] for valid Indian phone numbers which will be used for sending the SMS.

  6. Under Target, select AWS Lambda for Target Service. Select the Lambda function created in Step 2 under Function. Click Create Pipe below.

    image

Step 4. SNS Setup

Configuring AWS SNS

  1. Go to Services > Simple Notification Service > Text Messaging(SMS) > Sandbox destination phone numbers > Add phone number.

    image

  2. Add a phone number that may be used for testing purposes for verification by Amazon. Follow the steps until the phone number appears under the sandbox showing Status:

    Verified

    image

Resources