<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: pramodbs543</title>
    <description>The latest articles on DEV Community by pramodbs543 (@pramodbs543).</description>
    <link>https://dev.to/pramodbs543</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1111333%2Fac3bbcc8-ceae-438e-b544-82cb6e3fd6c1.jpg</url>
      <title>DEV Community: pramodbs543</title>
      <link>https://dev.to/pramodbs543</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pramodbs543"/>
    <language>en</language>
    <item>
      <title>How to connect AWS Lambda to a Database in a Private subnet in a VPC ?</title>
      <dc:creator>pramodbs543</dc:creator>
      <pubDate>Mon, 24 Jul 2023 09:56:07 +0000</pubDate>
      <link>https://dev.to/pramodbs543/how-to-connect-aws-lambda-to-a-database-in-a-private-subnet-in-a-vpc--a1o</link>
      <guid>https://dev.to/pramodbs543/how-to-connect-aws-lambda-to-a-database-in-a-private-subnet-in-a-vpc--a1o</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;u&gt;Overview&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
By Default, lambda function is launched outside our VPC. Therefore it can not access resources such as RDS, ElastiCache, internal ALB, etc in the VPC. So in order to allow lambda access our private resources, we have to define VPC ID, subnets, Security groups. Lambda will create elastic network interface(ENI) in private subnet which allows it connectivity.&lt;/p&gt;

&lt;p&gt;In this small project we will understand&lt;br&gt;
1)AWS lambda connectivity with the database in a private subnet.&lt;br&gt;
2)How to install and use MariaDB database server on EC2 instance.&lt;br&gt;
3)How to store and use the Database credentials securely in AWS secret Manager.&lt;br&gt;
4)How to add pymysql library as lambda layer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You can simple launch RDS databse in private subnet instead of installing it on EC2 instance. But here I wanted to try it on EC2(less costly also).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Prerequisite&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
1)AWS Account.&lt;br&gt;
2)Little experience with Python.&lt;br&gt;
3)Understanding of VPC,Subnets,Security Groups,etc.&lt;br&gt;
4)Familiarity with AWS lambda.&lt;br&gt;
Thats it..Lets Start.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Step1: Set up VPC:&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
To create a VPC use the terraform script. &lt;br&gt;
&lt;em&gt;git clone &lt;a href="https://github.com/pramodbs543/Terraform/tree/main/Simple_VPC" rel="noopener noreferrer"&gt;https://github.com/pramodbs543/Terraform/tree/main/Simple_VPC&lt;/a&gt;&lt;/em&gt;&lt;br&gt;
Here You have to just 1)store the Access key and Secret key as environment variables.(Shown in providers.tf file) 2)Change the Region in terraform.tfvars file.&lt;strong&gt;3)By default the backend.tf file stores tfstate file in S3 backend. You have to create respective S3 bucket and Dynamo DB for this. But if you want to skip this, simply delete the backend.tf file.&lt;/strong&gt; Apply following commands.&lt;/p&gt;

&lt;p&gt;terraform init&lt;br&gt;
terraform apply -auto-approve&lt;/p&gt;

&lt;p&gt;VPC is ready.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Step 2 Creat an IAM Role: &lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
For this We need to create an IAM role first with AmazonSSMManagedInstanceCore policy attached. This IAM role allows us to connect with EC2(For installing DB) even if the EC2 is in private subnet and has no key pair nor public IP.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe3pe1c2u8jvuezno33cd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe3pe1c2u8jvuezno33cd.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Facwwc3o1g2018c17t24n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Facwwc3o1g2018c17t24n.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Search for AmazonSSMManagedInstanceCore policy and attach this to the role. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3sds71fpc9rshmi7j0wb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3sds71fpc9rshmi7j0wb.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Give a name to the role and create role.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyqp4u2h0cixsi6zg4qaf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyqp4u2h0cixsi6zg4qaf.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Step 3: Create Security groups:&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
1)Security group for Lambda:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff16xntn3wr5yztwjwpfo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff16xntn3wr5yztwjwpfo.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fim098skyaslowe992x7b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fim098skyaslowe992x7b.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
2)Security group for DB.&lt;br&gt;
In inbound rule, for MYSQL/Aurora type give source as lambda SG.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa988n4ow5d9md61pfbs8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa988n4ow5d9md61pfbs8.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;Step 4:Launch an EC2 instance in private subnet of VPC:&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fydxsnx0f7hmdsd0xja0m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fydxsnx0f7hmdsd0xja0m.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Select ubuntu as an AMI, t2.medium, Proceed without a key pair. Select db-sg as security group we created. Keep Public IP disabed. Select the VPC in network section and select the private subnet.&lt;br&gt;
in Advance Details select the IAm role we created.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwot44u10xknhl1v6kga2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwot44u10xknhl1v6kga2.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
And launch the instance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Step 5: install MariaDB server on the EC2:&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
Connect to the EC2.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftw2u3745kuerxsv2gsj2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftw2u3745kuerxsv2gsj2.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Click in Session manager and click connect.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F79csfbw8x9rn3nq476eg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F79csfbw8x9rn3nq476eg.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Change to root directory.&lt;br&gt;
&lt;code&gt;$ cd /&lt;/code&gt;&lt;br&gt;
This command updates all packages to the latest version&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo apt update -y&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command installs MySQL server on your machine, it also creates a systemd service&lt;br&gt;
&lt;code&gt;sudo apt install -y mariadb-server&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command enables the service created in previous step&lt;br&gt;
&lt;code&gt;sudo systemctl enable mariadb&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command starts the MySQL server service on your Linux instance&lt;br&gt;
&lt;code&gt;sudo systemctl start mariadb&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command helps you to set root user password and improve your DB security&lt;br&gt;
&lt;code&gt;sudo mysql_secure_installation&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here, just hit enter as we have not set any password yet&lt;br&gt;
&lt;code&gt;Enter current password for root (enter for none):&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here Reply Y&lt;br&gt;
&lt;code&gt;Switch to unix_socket authentication [Y/n]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here, reply with Y&lt;br&gt;
&lt;code&gt;Change the root password? [Y/n]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Enter new password&lt;br&gt;
&lt;code&gt;New Password:&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Re-enter new password&lt;br&gt;
&lt;code&gt;Re-enter new Password:&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Say Y&lt;br&gt;
&lt;code&gt;Remove anonymous users? [Y/n]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Say Y&lt;br&gt;
&lt;code&gt;Disallow root login remotely? [Y/n]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Say N, as we would need them for verification &lt;br&gt;
&lt;code&gt;Remove test database and access to it? [Y/n]&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;Say Y&lt;br&gt;
&lt;code&gt;Reload privilege tables now? [Y/n]&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;Thanks for using MariaDB!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Verify the connection with the DB&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;mysql -h localhost -u root -p&lt;/code&gt;&lt;br&gt;
Enter password.&lt;br&gt;
Show Databases:&lt;br&gt;
&lt;code&gt;show databases;&lt;/code&gt;&lt;br&gt;
Create Database:&lt;br&gt;
&lt;code&gt;create database mydatabase;&lt;/code&gt;&lt;br&gt;
Switch to this Database:&lt;br&gt;
&lt;code&gt;use mydatabase;&lt;/code&gt;&lt;br&gt;
Create a Table inside this database:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

create table employees(eno int(10) primary key,ename varchar(20),esal double(10,2), eaddr varchar(30));



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;code&gt;describe employees;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frbhcaqrvdx4eij417tb4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frbhcaqrvdx4eij417tb4.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;exit;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Configure the DB to accept remote connections:&lt;/strong&gt;&lt;br&gt;
127.0.0.1(localhost) makes your database accessible locally. We have to make it accessible remotely. &lt;br&gt;
&lt;code&gt;$ cd /etc/mysql/mariadb.conf.d&lt;/code&gt;&lt;br&gt;
 &lt;code&gt;$ sudo vi 50-server.cnf&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;set bind-address=0.0.0.0 in place of 127.0.0.1&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fptxayoouqii1afroblqw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fptxayoouqii1afroblqw.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
&lt;code&gt;$ sudo systemctl restart mariadb&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ sudo ss -nlt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You will see 0.0.0.0:3306&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Filf5mstwwuulh39wymnn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Filf5mstwwuulh39wymnn.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, lets create an user which will have permissions to access mydatabase. Wildcard entry (%) allows this user01 to get connected from any host.&lt;br&gt;
&lt;code&gt;$ mysql -h localhost -u root -p&lt;/code&gt;&lt;br&gt;
Enter root password we set earlier.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CREATE USER 'user01'@'%' IDENTIFIED BY 'password543';&lt;/code&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

GRANT ALL PRIVILEGES ON mydatabase.* to user01@'%' IDENTIFIED BY 'password543' WITH GRANT OPTION;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;code&gt;FLUSH PRIVILEGES;&lt;/code&gt;&lt;br&gt;
exit&lt;/p&gt;

&lt;p&gt;...Database is all set now.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Step 6: AWS Secret manager to store Db credentials:&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
Select Secrets Manager in AWS.&lt;br&gt;
Store a new secret.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1utsbyjpo38odi95me1p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1utsbyjpo38odi95me1p.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fchj3l0y4u76oya9a45os.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fchj3l0y4u76oya9a45os.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Now, in the bottom, in server address enter private IP of EC2 instance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F25c084ktqtbscepnrdsh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F25c084ktqtbscepnrdsh.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Give the secret a name and hit Next.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjmqbi2yppppu46ytchqg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjmqbi2yppppu46ytchqg.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Hit NEXT again. Lastly hit Store the secret.(Note down your secret name. In this case "mariadbsecret")&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Step 7: Create a Lambda Function.&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fermsucf52iohu8cbhap0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fermsucf52iohu8cbhap0.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffx1mbqlpx9dgenqhtj8g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffx1mbqlpx9dgenqhtj8g.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Attach a role which has AWSsecretmanager policy attached to it.(We need to access the secrets from secret manager)&lt;/p&gt;

&lt;p&gt;Select the VPC now.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fltz54a2rzq03117hmzdf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fltz54a2rzq03117hmzdf.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Select both subnets for high availability and lambda security group.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F45r5lgx552385eqbjgdz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F45r5lgx552385eqbjgdz.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hit on Create function.&lt;br&gt;
&lt;strong&gt;Add pymysql library as lambda layer:&lt;/strong&gt;&lt;br&gt;
You will need python installed on your local Windows PC and the python version should match the Runtime version you selected for your Lambda function, in this case Python 3.10. You also need to install pip so that you can download the pymysql package.&lt;br&gt;
Once you have pip installed on your PC, open the command prompt and navigate to your desired directory and run the following command.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pip install --target ./python pymysql&lt;/code&gt;&lt;br&gt;
This will create a folder called python in the desired directory. You will then need to compress the python folder as a zip file so that we can upload it to AWS.&lt;br&gt;
In the Lambda console window, select the Layers option from the left side menu and click ‘Create layer’. Give your layer a name of ‘pymysql’ and upload the zip file that you just created. Select Python 3.10 as a Compatible runtime and click ‘Create’.&lt;/p&gt;

&lt;p&gt;Click on lambda function. Scroll to bottom. There you will find Layers. Add layer pymysql.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frtzpp54fobfubn8tle0x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frtzpp54fobfubn8tle0x.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Layer source as custom layers. Then from drop down select pymysql.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs45ki77c9zp612aeon83.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs45ki77c9zp612aeon83.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now copy the code from &lt;br&gt;
&lt;a href="https://github.com/pramodbs543/lambda-mysqlonEC2" rel="noopener noreferrer"&gt;https://github.com/pramodbs543/lambda-mysqlonEC2&lt;/a&gt;&lt;br&gt;
employees.py for lambda function. event file for providing json input to the code. The entries in the even file will be stored in database.&lt;/p&gt;

&lt;p&gt;Once you Test the code, you will get success message.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbpsdwdis6pj5ks6pgbmc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbpsdwdis6pj5ks6pgbmc.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The records in the database:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgcqvrbl9dg5q7djbyu9n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgcqvrbl9dg5q7djbyu9n.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
The Architecture:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8oc9yvmpvy3cmnux6qd7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8oc9yvmpvy3cmnux6qd7.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>lambda</category>
      <category>database</category>
      <category>vpc</category>
    </item>
    <item>
      <title>Serverless web application using AWS amplify, API gateway, Lambda and DynamoDB</title>
      <dc:creator>pramodbs543</dc:creator>
      <pubDate>Thu, 13 Jul 2023 04:50:22 +0000</pubDate>
      <link>https://dev.to/pramodbs543/serverless-web-application-using-aws-amplify-api-gateway-lambda-and-dynamodb-jo6</link>
      <guid>https://dev.to/pramodbs543/serverless-web-application-using-aws-amplify-api-gateway-lambda-and-dynamodb-jo6</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PTXhJooi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3fm88aytbchnm887qbc4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PTXhJooi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3fm88aytbchnm887qbc4.png" alt="Image description" width="800" height="426"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Use Case: This small project lets you use AWS services such as AWS Amplify, API gateway, Lambda, IAM service and DynamoDB to host a small web application. Users will be able to access the web app using an URl and they can fill the details such as name, weight, height. Based on the information, the BMI will be calculated and the details will be stored in Dynamo DB.&lt;/p&gt;

&lt;p&gt;1)AWS Aplify: AWS Amplify is a complete solution that lets frontend web and mobile developers easily build, ship, and host full-stack(Dynamic-interactive) applications on AWS, with the flexibility to leverage the breadth of AWS services as use cases evolve. No cloud expertise needed. &lt;/p&gt;

&lt;p&gt;2)AWS API Gateway: Using API Gateway, you can create RESTful APIs and WebSocket APIs that enable real-time two-way communication applications. API Gateway supports containerized and serverless workloads, as well as web applications.&lt;/p&gt;

&lt;p&gt;3)AWS Lambda: AWS Lambda is a serverless, event-driven compute service that lets you run code for virtually any type of application or backend service without provisioning or managing servers. Here we are triggering lambda functions using API calls.&lt;/p&gt;

&lt;p&gt;4)Dynamo DB: fully managed, serverless, key-value NoSQL database designed to run high-performance applications at any scale.&lt;/p&gt;

&lt;p&gt;Lets Deep dive into the steps now.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Step 1: Set Up database&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
Create Dynamo Db table: Search for Dynamo Db and create table&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wHEagzA1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ictoaqp0m9apes588n6n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wHEagzA1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ictoaqp0m9apes588n6n.png" alt="Image description" width="800" height="295"&gt;&lt;/a&gt;&lt;br&gt;
Enter the name of table, partition key and sort key.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zNa9-pL5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b56lqwxcfkhg87o5ryva.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zNa9-pL5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b56lqwxcfkhg87o5ryva.png" alt="Image description" width="800" height="539"&gt;&lt;/a&gt;&lt;br&gt;
Keep other things default and hit on create table.&lt;br&gt;
Our table is created. Now go to the table and find out its ARN. We need this ARN while giving permissions to Lambda to access this table.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--l8nOh-Ni--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/583o45fbj6lk83zh6s8f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--l8nOh-Ni--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/583o45fbj6lk83zh6s8f.png" alt="Image description" width="800" height="227"&gt;&lt;/a&gt;&lt;br&gt;
Under general information, additional info you will find the ARN. Copy it and store in notepad.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XuAvooG---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8rl4cwv2vuhcyz37qz4m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XuAvooG---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8rl4cwv2vuhcyz37qz4m.png" alt="Image description" width="800" height="566"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;u&gt;Step 2: Create an IAM role for AWS Lambda function.&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
Go To IAM service. &lt;br&gt;
Hit on Roles and then Create role.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n0VIR5zN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a46o0icd1okp1edbsk8c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n0VIR5zN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a46o0icd1okp1edbsk8c.png" alt="Image description" width="800" height="383"&gt;&lt;/a&gt;&lt;br&gt;
Select AWS Service and Lambda and hit Next. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nXEq2gtE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/boitnedxcnqvlpfzp0ku.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nXEq2gtE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/boitnedxcnqvlpfzp0ku.png" alt="Image description" width="800" height="678"&gt;&lt;/a&gt;&lt;br&gt;
Now we have to create a policy to atach to the Role we created. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oYz6WD5Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/01tmzlsj76b3znp5ar4i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oYz6WD5Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/01tmzlsj76b3znp5ar4i.png" alt="Image description" width="800" height="257"&gt;&lt;/a&gt;&lt;br&gt;
Cleck on JSON. (We will create a policy using JSON)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HzWAQpWl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p60kdhiy3l0whxivk9d7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HzWAQpWl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p60kdhiy3l0whxivk9d7.png" alt="Image description" width="800" height="404"&gt;&lt;/a&gt;&lt;br&gt;
Remove the default JSON code. Paste the code from the link and in the last modify the DynamoDb table ARN(We noted down):&lt;br&gt;
&lt;a href="https://github.com/pramodbs543/AWS-API-Lambda-DB/blob/main/Lambda-Role-policy"&gt;https://github.com/pramodbs543/AWS-API-Lambda-DB/blob/main/Lambda-Role-policy&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hit Next and give the policy a name. Hit on create policy bottom right corner.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v55J8fDR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gryy1negkzq4e3ry4y1s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v55J8fDR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gryy1negkzq4e3ry4y1s.png" alt="Image description" width="800" height="473"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Goto Roles again. Create Role. Select AWS service, Lambda and hit next. Now select the policy we have created.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uem3OUzC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/say847jv717nbpw3y2cs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uem3OUzC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/say847jv717nbpw3y2cs.png" alt="Image description" width="800" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on the next botton at the right bottom corner. Give name to the role. Lastly hit the Create role on right bottom. Our role is created successfully.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gfmeuEH9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qvaml5fid0ddigjuvc87.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gfmeuEH9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qvaml5fid0ddigjuvc87.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: You can attach cloudwatch logs policy also to your lambda role in order to debug the issue with lamda function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Step 3: Create Lambda Function.&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
Search for lambda. Create a function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fsEuvRrp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/exhkas5w3by0dn27m26r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fsEuvRrp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/exhkas5w3by0dn27m26r.png" alt="Image description" width="800" height="203"&gt;&lt;/a&gt;&lt;br&gt;
Select Python as our Run time. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6jUZFGS7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/12mgd2er88b7hwj538cx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6jUZFGS7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/12mgd2er88b7hwj538cx.png" alt="Image description" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the same window, under change default execution role select the role we created for lambda. Hit on create function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rUiAB9s4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/156eeuctif16o4hndze4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rUiAB9s4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/156eeuctif16o4hndze4.png" alt="Image description" width="800" height="251"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we will paste our code here.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BC5eYnBf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8hzkvpqnwv0v6lrsfp7v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BC5eYnBf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8hzkvpqnwv0v6lrsfp7v.png" alt="Image description" width="800" height="368"&gt;&lt;/a&gt;&lt;br&gt;
Copy the code from &lt;a href="https://github.com/pramodbs543/AWS-API-Lambda-DB/blob/main/lambda-function"&gt;https://github.com/pramodbs543/AWS-API-Lambda-DB/blob/main/lambda-function&lt;/a&gt;  And paste in the function box above. You have to change the DynamoDb table name at line 14.&lt;/p&gt;

&lt;p&gt;Then Hit on the Deploy button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AK25t-CP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c5obzlenhfkhhbg7c62k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AK25t-CP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c5obzlenhfkhhbg7c62k.png" alt="Image description" width="800" height="314"&gt;&lt;/a&gt;&lt;br&gt;
Now lets test weather the code works fine or not. Click on the Test on the same window.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--V6O6ou_5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ldu1xak7zyzm2yi6rmfs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V6O6ou_5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ldu1xak7zyzm2yi6rmfs.png" alt="Image description" width="800" height="369"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--T3NQqAU---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/luxnug54xcxfohwawbro.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--T3NQqAU---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/luxnug54xcxfohwawbro.png" alt="Image description" width="800" height="361"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In Event JSON We have to enter in correct format(as our code is configured)&lt;br&gt;
This is sample Json.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KaHbvego--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/73d3uy1pjiscxckurr1q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KaHbvego--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/73d3uy1pjiscxckurr1q.png" alt="Image description" width="433" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on the Test button. the code will execute with the input provided in JSON format. Now coma back to code tab. You will see the output returned by our lambda function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RVpPFg3e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0snukgyw96ywr7nr2k1m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RVpPFg3e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0snukgyw96ywr7nr2k1m.png" alt="Image description" width="800" height="397"&gt;&lt;/a&gt;&lt;br&gt;
Lets go to our Dynamo Db table and explore table items. We will check the entries in the table.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R9_ikkzO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vz5smeynpw84p6vxn7r2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R9_ikkzO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vz5smeynpw84p6vxn7r2.png" alt="Image description" width="800" height="386"&gt;&lt;/a&gt;&lt;br&gt;
Select Scan and hit on Run button. You will see the entries in the table.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---Jw84mZY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/enlbg5ybmif1r4kxw9v2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---Jw84mZY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/enlbg5ybmif1r4kxw9v2.png" alt="Image description" width="800" height="695"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now lets set up our APIs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Step 4: Create AWS API:&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
Go to AWS API service. Select Rest API and click on Build.&lt;br&gt;
Create New API. Give API a name.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--q_M96Eza--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w2vh030evsohzl53l63f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--q_M96Eza--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w2vh030evsohzl53l63f.png" alt="Image description" width="800" height="348"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on Actions, create a method with POST. Select integration type as Lambda function(Default it is). Enter our lambda function name(Drop down, you just start typing the name). Click on save.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WGyTn5mz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ycqm30kgyliv6nmdgw7p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WGyTn5mz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ycqm30kgyliv6nmdgw7p.png" alt="Image description" width="800" height="365"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Enable CORS for cross domain access. (Our APIs will be access by AWS Amplify which has a different domain). After enabling CORS, *&lt;em&gt;Deploy the API *&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LzZMiAzA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zykbbxk5taz2sbqwxixq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LzZMiAzA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zykbbxk5taz2sbqwxixq.png" alt="Image description" width="800" height="325"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can test the API by clicking the Test button. But don't forget to provide the JSON input.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BRqoYNkA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eji1hcuvr2ttb3wlr1fj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BRqoYNkA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eji1hcuvr2ttb3wlr1fj.png" alt="Image description" width="800" height="246"&gt;&lt;/a&gt;&lt;br&gt;
Click on Action, Deploy API. Enter Deployment stage as New stage. Stage name. Hit the Deploy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QoK64pDm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yo5bja79gat17jhvwei0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QoK64pDm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yo5bja79gat17jhvwei0.png" alt="Image description" width="800" height="509"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will get one URL. This is our end API end point. Note it down because we need this to be added on out front end web app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--W6ohgDRH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ah48oujymgdz5w9u198e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--W6ohgDRH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ah48oujymgdz5w9u198e.png" alt="Image description" width="800" height="68"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Step 5:&lt;/u&gt;&lt;/strong&gt;: Create index.html file using the code from &lt;a href="https://github.com/pramodbs543/AWS-API-Lambda-DB/blob/main/index.html"&gt;https://github.com/pramodbs543/AWS-API-Lambda-DB/blob/main/index.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Don't forget to modify the API end pint at line number 61.&lt;/p&gt;

&lt;p&gt;Create a zip folder of index.html file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Step 6:&lt;/u&gt;&lt;/strong&gt; Deploy the front end web application on AWS amplify.&lt;br&gt;
Search AWS amplify. Click on get started.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TEgLJ3hU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z1lj75gfdfuy4ahiul38.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TEgLJ3hU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z1lj75gfdfuy4ahiul38.png" alt="Image description" width="800" height="380"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fH2dHFbd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4mz1x0y7x0ta6mobzpun.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fH2dHFbd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4mz1x0y7x0ta6mobzpun.png" alt="Image description" width="800" height="474"&gt;&lt;/a&gt;&lt;br&gt;
Deploy without git provider.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4j5vojSG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eja235jmejt41kylzw3x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4j5vojSG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eja235jmejt41kylzw3x.png" alt="Image description" width="800" height="456"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zMAHVtNA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4nevfluifpzn8dtnkxkq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zMAHVtNA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4nevfluifpzn8dtnkxkq.png" alt="Image description" width="800" height="565"&gt;&lt;/a&gt;&lt;br&gt;
Drag and deploy the zip folder here. Save and deploy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AUGwC9np--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lsj9jhiqbaes7m4a1jht.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AUGwC9np--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lsj9jhiqbaes7m4a1jht.png" alt="Image description" width="800" height="274"&gt;&lt;/a&gt;&lt;br&gt;
Our application is successfully deployed. We are ready to go. Open the domain url. You will see the efforts paid off....&lt;/p&gt;

&lt;p&gt;The Window is as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kqkyp84I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pba40d7lc0y5r59j7z53.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kqkyp84I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pba40d7lc0y5r59j7z53.png" alt="Image description" width="800" height="295"&gt;&lt;/a&gt;&lt;br&gt;
As soon as you hit the calculate and record button, you will get response in alert format as shown on the screen. Parallely the records will be stored in DynamoDB table as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S88fdOcs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yfoeyrgx01316oo070it.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S88fdOcs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yfoeyrgx01316oo070it.png" alt="Image description" width="800" height="292"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>devops</category>
      <category>api</category>
      <category>lambda</category>
    </item>
  </channel>
</rss>
