Showing posts with label DynamoDB. Show all posts
Showing posts with label DynamoDB. Show all posts
Deploy Sever-less Application using Terraform (AWS API Gateway, Lambda and DynamoDB)
Nowadays, A popular approach to running "serverless" web applications is to implement the application functionality as one or more functions in AWS Lambda and then expose these for public consumption using Amazon API Gateway without having to think about infrastructure.
With my style, I am going through a procedure to deploy such a web application using terraform.
Note: In order to follow this guide you will need an AWS account and to have Terraform installed. Configure your credentials so that Terraform is able to act on your behalf.
or
you can simply clone my repo and place your access key in terraform.tfvars file.
Before moving onto the deployment refer below figure to understand how AWS full architecture works.
Our ideas is simple, User fille the feedback form and click submit, on submission write to the DynamoDB (post).
Refer the form below
Steps involved in the deployment
1. Create DynamoDB
2. Create AWS IAM Role to assume on behalf you
3. Create a Lamda function
3.1. Create put Item function
4. Create Api Gateway
4.1. Create api Resourse
4.3 Create api method
4.4. Create invoke function to invoke lamda
5. Deploy API and Allowing API Gateway to Access Lambda.
6. Copy the API ARN and paste to the form post URL to test (POSTMAN can also be used)
6. Copy the API ARN and paste to the form post URL to test (POSTMAN can also be used)
Note find the full repo here
1. Create DynamoDB
Amazon DynamoDB is a fully managed NoSQL database service that provides fast and predictable performance with seamless scalability. – from AWS
Amazon DynamoDB is a fully managed NoSQL database service that provides fast and predictable performance with seamless scalability. – from AWS
Create DynamoDB with primary as email
[fayasak@controller]$ cat dynamo.tfresource "aws_dynamodb_table" "dynamodb"{
name="mywebsite"
hash_key="email"
attribute=[
{
name="email"
type="s"
}
]
}
2. Create AWS IAM Role to assume on behalf of you
Before specifying the Lambda Functions we have to create permissions for our functions to use. This makes sure that our lambda function has permission to access DynamoDB resources.
Note: I have created a policy full access policy for dynamoDB. if you want you can change policy as per you want.
EX: "dynamodb:Scan","dynamodb:BatchWriteItem","dynamodb:PutItem"
Before specifying the Lambda Functions we have to create permissions for our functions to use. This makes sure that our lambda function has permission to access DynamoDB resources.
[fayasak@controller]$ cat iam.tf#create a role for lamda access aws resoucesresouce "aws_iam_role" "lamda-iam"{ #role name name="lamda-dynamodb" #assume role to a services assume_role_policy =<<EOF { "Version": "2012-10-17", "Statement": [ { "Action": "sts:AssumeRole", "Principal": { "Service": "lambda.amazonaws.com" }, "Effect": "Allow", "Sid": "" } ] }EOF}# create policy for role to assume dynamodbresource "aws_iam_role_policy" "dynamodb-lambda-policy"{ name = "dynamodb_lambda_policy" role = "${aws_iam_role.lamda-iam.id}"
policy = <<EOF { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "dynamodb:*" ], "Resource": "${aws_dynamodb_table.dynamodb.arn}" } ] } EOF}Note: I have created a policy full access policy for dynamoDB. if you want you can change policy as per you want.
EX: "dynamodb:Scan","dynamodb:BatchWriteItem","dynamodb:PutItem"
Subscribe to:
Posts (Atom)

