<?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: Kousalya S</title>
    <description>The latest articles on DEV Community by Kousalya S (@kousalya_s_1e656b83b89b93).</description>
    <link>https://dev.to/kousalya_s_1e656b83b89b93</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1692513%2Fc7c6e374-c181-4e95-bdb2-fc0de879cce2.png</url>
      <title>DEV Community: Kousalya S</title>
      <link>https://dev.to/kousalya_s_1e656b83b89b93</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kousalya_s_1e656b83b89b93"/>
    <language>en</language>
    <item>
      <title>Architect and Build an End-to-End AWS Web Application</title>
      <dc:creator>Kousalya S</dc:creator>
      <pubDate>Tue, 09 Jul 2024 07:56:13 +0000</pubDate>
      <link>https://dev.to/kousalya_s_1e656b83b89b93/architect-and-build-an-end-to-end-aws-web-application-13ib</link>
      <guid>https://dev.to/kousalya_s_1e656b83b89b93/architect-and-build-an-end-to-end-aws-web-application-13ib</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;Architect and build an end-to-end AWS web application with AWS Amplify for seamless front-end hosting, AWS Lambda for serverless functions, Amazon API Gateway for managing APIs, Amazon DynamoDB for scalable NoSQL databases, and IAM roles for secure access management. This integration ensures a robust, scalable, and secure application infrastructure.&lt;/p&gt;

&lt;h2&gt;
  
  
  AWS Services used in this tutorial
&lt;/h2&gt;

&lt;p&gt;Amplify&lt;br&gt;
Amazon API Gateway&lt;br&gt;
AWS Lambda&lt;br&gt;
AWS IAM&lt;br&gt;
Amazon DynamoDB&lt;/p&gt;
&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;- An AWS account&lt;/li&gt;
&lt;li&gt;- A basic understanding of AWS.&lt;/li&gt;
&lt;li&gt;- A text or code editor. I am using VSCode. &lt;/li&gt;
&lt;li&gt;- A basic understanding of HTML, CSS and JavaScript is recommended but not necessary.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Architecture Diagram
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl564g5o6olub6m3j1o6g.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl564g5o6olub6m3j1o6g.jpeg" alt="Image description" width="800" height="335"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: Create an index.html file
&lt;/h2&gt;

&lt;p&gt;Go on and create an index.html file in any folder of your choice and add the following code to it using a text editor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8" /&amp;gt;
    &amp;lt;link rel="preconnect" href="https://fonts.googleapis.com" /&amp;gt;
    &amp;lt;link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /&amp;gt;
    &amp;lt;link
      href="https://fonts.googleapis.com/css2?family=Rajdhani:wght@400;500;600&amp;amp;display=swap"
      rel="stylesheet"
    /&amp;gt;
    &amp;lt;title&amp;gt;Exponential Math ⚡️&amp;lt;/title&amp;gt;
    &amp;lt;!-- Styling for the web page --&amp;gt;
    &amp;lt;style&amp;gt;
      h1 {
        color: #fff;
        text-align: center;
        text-transform: uppercase;
        font-size: 50px;
        font-weight: 600;
      }
      body {
        background-color: #34495e;
        font-family: 'Rajdhani', sans-serif;
        display: flex;
        justify-content: center;
        align-items: center;
        position: relative;
      }
      label {
        color: #ffa801;
        font-size: 25px;
        margin-top: 20px;
      }

      label:last-of-type {
        margin-left: 20px;
      }
      button {
        background-color: #05c46b;
        border: none;
        color: #fff;
        font-size: 20px;
        font-weight: bold;
        margin-left: 30px;
        margin-top: 20px;
        padding: 10px 20px;
        font-family: 'Rajdhani', sans-serif;
        cursor: pointer;
      }
      input {
        color: #222629;
        border: none;
        font-size: 20px;
        margin-left: 10px;
        margin-top: 20px;
        padding: 10px 20px;
        max-width: 150px;
        outline-color: #05c46b;
      }
      div {
        width: auto;
        position: absolute;
        top: 35vh;
      }
    &amp;lt;/style&amp;gt;
    &amp;lt;script&amp;gt;
      // callAPI function that takes the base and exponent numbers as parameters
      var callAPI = (base, exponent) =&amp;gt; {
        // instantiate a headers object
        var myHeaders = new Headers();
        // add content type header to object
        myHeaders.append("Content-Type", "application/json");
        // using built in JSON utility package turn object to string and store in a variable
        var raw = JSON.stringify({ base: base, exponent: exponent });
        // create a JSON object with parameters for API call and store in a variable
        var requestOptions = {
          method: "POST",
          headers: myHeaders,
          body: raw,
          redirect: "follow",
        };
        // make API call with parameters and use promises to get response
        fetch("YOUR_API_GATEWAY_ENDPOINT", requestOptions)
          .then((response) =&amp;gt; response.text())
          .then((result) =&amp;gt; alert(JSON.parse(result).body))
          .catch((error) =&amp;gt; console.log("error", error));
      };
    &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Exponential Math ⚡️&amp;lt;/h1&amp;gt;
      &amp;lt;form&amp;gt;
        &amp;lt;label&amp;gt;Base number:&amp;lt;/label&amp;gt;
        &amp;lt;input type="number" id="base" /&amp;gt;
        &amp;lt;label&amp;gt;to the power&amp;lt;/label&amp;gt;
        &amp;lt;input type="number" id="exponent" /&amp;gt;
        &amp;lt;!-- set button onClick method to call function we defined passing input values as parameters --&amp;gt;
        &amp;lt;button
          type="button"
          onclick="callAPI(document.getElementById('base').value,document.getElementById('exponent').value)"
        &amp;gt;
          CALCULATE
        &amp;lt;/button&amp;gt;
      &amp;lt;/form&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;This code constitutes our web page i.e. the frontend of our application which we are going to deploy to AWS Amplify.&lt;/p&gt;

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

&lt;p&gt;That’s how our final webpage looks. You can play around with the colours to change the look and feel of the webpage. Now, compress your index.html file i.e. make it a zip file. We are going to use this zip file in the next step.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Deploying our web app on Amplify
&lt;/h2&gt;

&lt;p&gt;We are using Amplify for this step.AWS Amplify is a set of tools and services for building scalable mobile and web applications, providing backend services, front-end libraries, and hosting solutions with a focus on ease of use.&lt;br&gt;
Login into the AWS management console and search for Amplify in the  management console. Once you have searched for and navigated to AWS Amplify.&lt;/p&gt;

&lt;p&gt;1.Click on the Get Started button(will take you to another page where you choose the source of your code i.e. where Amplify is going to get the code you want to deploy from.)&lt;br&gt;
2.Select the “Deploy without Git provider”.(Since the application code we want to host is not on any Git provider and Clicking on the Continue button takes you to the page)&lt;br&gt;
3.Type out the name you’ll like to give your app. I named my app ExponentialMath.&lt;br&gt;
4.In the Environment name input box, write dev Now drag and drop your index.zip file into the area.&lt;br&gt;
5.Next click on the save and deploy button.&lt;/p&gt;

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

&lt;p&gt;If the deployment was successful, the resulting page will be similar to the one in the image shown above. Clicking the URL that’s on that page will open our webpage.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 3: Working on our application logic
&lt;/h2&gt;

&lt;p&gt;We are going to use AWS Lambda for this step.AWS Lambda is a serverless computing service that runs code in response to events, automatically managing the underlying infrastructure, allowing you to focus solely on code without provisioning servers.&lt;/p&gt;

&lt;p&gt;Using Lambda, we are going to write some Python code using the Python Math library to carry out the calculations feature of our application.&lt;/p&gt;

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

&lt;p&gt;Click on the Create a function button as shown in the image above. On the resulting page select Author from scratch, input a name for your function (as you can see in the image below, I called my lambda function ExponentialMathFunction ). Now select the runtime for the function. As pointed out earlier, we are using Python so select the Python runtime.&lt;/p&gt;

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

&lt;p&gt;On the resulting page, replace the code in the lambda_function.py file with the code below, use Ctrl + S to save it and then click on the Deploy button to deploy the function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# import the JSON utility package
import json
# import the Python math library
import math
# define the handler function that the Lambda service will use an entry point
def lambda_handler(event, context):
# extract the two numbers from the Lambda service's event object
    mathResult = math.pow(int(event['base']), int(event['exponent']))
    # return a properly formatted JSON object
    return {
    'statusCode': 200,
    'body': json.dumps('Your result is ' + str(mathResult))
    }

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

&lt;/div&gt;



&lt;p&gt;What the code does is, it imports the JSON utility package and the Python Math library which will enable us to do our calculations.&lt;/p&gt;

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

&lt;p&gt;Now that our lambda function is deployed, let’s configure a test event and test it to see if it is working&lt;/p&gt;

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

&lt;p&gt;Replaced the JSON code shown in the image above with the code below and click on the Save button.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "base": 3,
  "exponent": 2
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that our test event is configured and saved, we can run a test. So click on the blue Test button to run a test for our lambda function.&lt;/p&gt;

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

&lt;p&gt;As you can see in the image above, our test has returned a response with a status code of 200 (which means that the test was successful) and a response body which says our result is 9. This means our function is working just fine. Let’s move on to the fourth step.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Make it possible to invoke the lambda function we created
&lt;/h2&gt;

&lt;p&gt;After having created a lambda function that will perform our calculations, we need to make it possible for our hosted web application to be able to invoke it when needed.Amazon API Gateway is a managed service that allows developers to create, publish, maintain, monitor, and secure APIs at any scale, enabling backend services for web, mobile, and serverless applications.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open a new management console window in a new tab, search for and navigate to API Gateway.&lt;/li&gt;
&lt;li&gt;Click on the Create API button. &lt;/li&gt;
&lt;li&gt;Scroll down to the REST API section and click on the Build button.&lt;/li&gt;
&lt;li&gt;Add a name for your API click on the Create API button.(make sure you are in the Resources tab.)&lt;/li&gt;
&lt;li&gt;Make sure you have the forward slash selected as indicated.&lt;/li&gt;
&lt;li&gt;Select the Create Method option.&lt;/li&gt;
&lt;li&gt;Select POST and then click on the check icon that appears next to it. The reason we are selecting POST is that our application submits numbers for a calculation to be performed.&lt;/li&gt;
&lt;li&gt;Since we are using a lambda function for our application logic, select Lambda Function as the Integration type, input the name of our lambda function in the appropriate input box and then click on the Save button. On the dialogue box that appears after clicking Save, click OK to permit API Gateway to invoke the lambda function.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;9.The next thing we have to do is enable CORS (Cross Origin Resource Sharing). What CORS does is that it allows resources on one domain to access resources on another domain. Click the Actions button and select Enable CORS. Make sure you have selected POST sitting directly below the forward slash before you select Enable CORS&lt;/p&gt;

&lt;p&gt;10.let’s deploy the API so we can be able to test it.&lt;/p&gt;

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

&lt;p&gt;Copy your Invoke URL and keep it safe somewhere because we are going to use it later on. Now go back to the resource tab and click on POST to see a flow of how the API works. click on the Test .&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fswxfdtioc9wkf24epsyb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fswxfdtioc9wkf24epsyb.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5rsjootwjlx8bvfpc5go.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5rsjootwjlx8bvfpc5go.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Famza9jt7keuvmqkruq3m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Famza9jt7keuvmqkruq3m.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 5: Configure a database where we will store all the results of our calculations.
&lt;/h2&gt;

&lt;p&gt;We are going to use DynamoDB to achieve our objective. Our application doesn’t necessarily need to store the results of calculations in a database. This step is added just to show you have you can store application data in a database. DynamoDB is a managed NoSQL database service that provides fast performance with seamless scalability. In DynamoDB, data is stored in key-value pairs.&lt;/p&gt;

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

&lt;p&gt;Click on Create table&lt;/p&gt;

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

&lt;p&gt;Fill in the necessary details as indicated in the image above and click on Create table This creates a new DynamoDB table for us. Click on the table name to open it.&lt;/p&gt;

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

&lt;p&gt;copy and keep the ARN of your database table somewhere safe as we are going to use it soon.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 6: Grant our lambda function permission to write results to DynamoDB
&lt;/h2&gt;

&lt;p&gt;we are going to leverage the IAM roles feature of AWS IAM. IAM is a service provided by AWS that allows you to manage access to your AWS resources. An IAM role is a set of permissions that you can temporarily assign to an entity or an AWS service.&lt;/p&gt;

&lt;p&gt;Go back to the browser tab where you have AWS Lambda open.&lt;/p&gt;

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

&lt;p&gt;Click on the Role name highlighted in the image. This will open IAM in a new tab.&lt;/p&gt;

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

&lt;p&gt;Click on the Add permissions dropdown button and select Create inline policy as shown in the image above.&lt;/p&gt;

&lt;p&gt;Make sure you are in the JSON tab and replace the JSON policy with the code below. Make sure you replace "YOUR-TABLE-ARN" with the actual table ARN you copied earlier. Once you are done, click on the Next button.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
"Version": "2012-10-17",
"Statement": [
    {
        "Sid": "LambdaFunctionExecutionPolicy",
        "Effect": "Allow",
        "Action": [
            "dynamodb:PutItem",
            "dynamodb:DeleteItem",
            "dynamodb:GetItem",
            "dynamodb:Scan",
            "dynamodb:Query",
            "dynamodb:UpdateItem"
        ],
        "Resource": "YOUR-TABLE-ARN"
    }
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What this policy does is it allows our lambda function to perform various actions on our DynamoDB table.&lt;/p&gt;

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

&lt;p&gt;Input a policy name as indicated in the image above and then click on the Create policy button to create the policy.&lt;/p&gt;

&lt;p&gt;Now that we have successfully made it possible for our lambda function to perform various actions on our DynamoDB table, let’s update our lambda function. Copy the code below and use it as a replacement for the current code in the lambda_function.py file found in the code tab of our lambda management console window and then use Ctrl + S to save the file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# import the JSON utility package
import json
# import the Python math library
import math
# import the AWS SDK (for Python the package name is boto3)
import boto3
# import two packages to help us with dates and date formatting
from time import gmtime, strftime
# create a DynamoDB object using the AWS SDK
dynamodb = boto3.resource('dynamodb')
# use the DynamoDB object to select our table
table = dynamodb.Table('ExponentialMathDatabase')
# store the current time in a human readable format in a variable
now = strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())
# define the handler function that the Lambda service will use an entry point
def lambda_handler(event, context):
# extract the two numbers from the Lambda service's event object
    mathResult = math.pow(int(event['base']), int(event['exponent']))
# write result and time to the DynamoDB table using the object we instantiated and save response in a variable
    response = table.put_item(
        Item={
            'ID': str(mathResult),
            'LatestGreetingTime':now
            })
# return a properly formatted JSON object
    return {
    'statusCode': 200,
    'body': json.dumps('Your result is ' + str(mathResult))
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;After updating and saving the code, make sure you deploy it by clicking on the Deploy button. Now click on Test, go back to the DynamoDB tab and open up our database table.&lt;/p&gt;

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

&lt;p&gt;Click on the Explore table items button to see if the results of the test were stored successfully.&lt;/p&gt;

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

&lt;p&gt;the results were stored successfully.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 7: Make it possible for our front-end to be able to hit the API Gateway Endpoint.
&lt;/h2&gt;

&lt;p&gt;We are getting close to the finish line!! As of this point, we can perform calculations by inputting numbers and using the CALCULATE button on our webpage because we can't invoke our calculations lambda function from the webpage. To make this possible, we have to connect our webpage to API Gateway using the API Gateway endpoint we copied earlier.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8" /&amp;gt;
    &amp;lt;link rel="preconnect" href="https://fonts.googleapis.com" /&amp;gt;
    &amp;lt;link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /&amp;gt;
    &amp;lt;link
      href="https://fonts.googleapis.com/css2?family=Rajdhani:wght@400;500;600&amp;amp;display=swap"
      rel="stylesheet"
    /&amp;gt;
    &amp;lt;title&amp;gt;Exponential Math ⚡️&amp;lt;/title&amp;gt;
    &amp;lt;!-- Styling for the web page --&amp;gt;
    &amp;lt;style&amp;gt;
      h1 {
        color: #fff;
        text-align: center;
        text-transform: uppercase;
        font-size: 50px;
        font-weight: 600;
      }
      body {
        background-color: #34495e;
        font-family: 'Rajdhani', sans-serif;
        display: flex;
        justify-content: center;
        align-items: center;
        position: relative;
      }
      label {
        color: #ffa801;
        font-size: 25px;
        margin-top: 20px;
      }

      label:last-of-type {
        margin-left: 20px;
      }
      button {
        background-color: #05c46b;
        border: none;
        color: #fff;
        font-size: 20px;
        font-weight: bold;
        margin-left: 30px;
        margin-top: 20px;
        padding: 10px 20px;
        font-family: 'Rajdhani', sans-serif;
        cursor: pointer;
      }
      input {
        color: #222629;
        border: none;
        font-size: 20px;
        margin-left: 10px;
        margin-top: 20px;
        padding: 10px 20px;
        max-width: 150px;
        outline-color: #05c46b;
      }
      div {
        width: auto;
        position: absolute;
        top: 35vh;
      }
    &amp;lt;/style&amp;gt;
    &amp;lt;script&amp;gt;
      // callAPI function that takes the base and exponent numbers as parameters
      var callAPI = (base, exponent) =&amp;gt; {
        // instantiate a headers object
        var myHeaders = new Headers();
        // add content type header to object
        myHeaders.append("Content-Type", "application/json");
        // using built in JSON utility package turn object to string and store in a variable
        var raw = JSON.stringify({ base: base, exponent: exponent });
        // create a JSON object with parameters for API call and store in a variable
        var requestOptions = {
          method: "POST",
          headers: myHeaders,
          body: raw,
          redirect: "follow",
        };
        // make API call with parameters and use promises to get response
        fetch("YOUR_API_GATEWAY_ENDPOINT", requestOptions)
          .then((response) =&amp;gt; response.text())
          .then((result) =&amp;gt; alert(JSON.parse(result).body))
          .catch((error) =&amp;gt; console.log("error", error));
      };
    &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Exponential Math ⚡️&amp;lt;/h1&amp;gt;
      &amp;lt;form&amp;gt;
        &amp;lt;label&amp;gt;Base number:&amp;lt;/label&amp;gt;
        &amp;lt;input type="number" id="base" /&amp;gt;
        &amp;lt;label&amp;gt;to the power&amp;lt;/label&amp;gt;
        &amp;lt;input type="number" id="exponent" /&amp;gt;
        &amp;lt;!-- set button onClick method to call function we defined passing input values as parameters --&amp;gt;
        &amp;lt;button
          type="button"
          onclick="callAPI(document.getElementById('base').value,document.getElementById('exponent').value)"
        &amp;gt;
          CALCULATE
        &amp;lt;/button&amp;gt;
      &amp;lt;/form&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace YOUR_API_GATEWAY_ENDPOINT with the API Gateway endpoint you copied earlier. Save your changes, delete the old index.zip and create a new one by zipping the updated index.html Go back to the AWS Amplify management console window.&lt;/p&gt;

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

&lt;p&gt;Drag and drop your index.zip file here so that our application can be redeployed. Now open the link to our webpage hosted on Amplify, input some numbers and click CALCULATE to perform some calculations. Our webpage will call API Gateway which then triggers our lambda function to perform calculations and store the results of the calculations in our DynamoDB table.&lt;/p&gt;

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

&lt;p&gt;Congratulations!!!You have successfully built an end-to-end, simple web application on AWS. &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Congratulations on completing this step-by-step tutorial on building a simple end-to-end web application using Amplify, AWS Lambda, API Gateway, IAM, and DynamoDB&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Automating Instance Management Using AWS Lambda and EventBridge</title>
      <dc:creator>Kousalya S</dc:creator>
      <pubDate>Mon, 08 Jul 2024 05:38:24 +0000</pubDate>
      <link>https://dev.to/kousalya_s_1e656b83b89b93/automating-instance-management-using-aws-lambda-and-eventbridge-26km</link>
      <guid>https://dev.to/kousalya_s_1e656b83b89b93/automating-instance-management-using-aws-lambda-and-eventbridge-26km</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;Automating instance management with AWS Lambda and EventBridge involves using EventBridge to trigger Lambda functions based on specific events or schedules. This setup can automatically start, stop, or manage EC2 instances, optimizing resource usage and costs by responding to predefined conditions or times.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are AWS Lambda?
&lt;/h2&gt;

&lt;p&gt;AWS Lambda is a serverless computing service that lets you run code without provisioning or managing servers. You write your code and upload it to Lambda, and it automatically scales and executes in response to events, charging only for compute time consumed. It supports various programming languages.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Amazon EventBridge?
&lt;/h2&gt;

&lt;p&gt;Amazon EventBridge is a serverless event bus service that makes it easy to connect applications using data from your applications, integrated SaaS applications, and AWS services. It allows you to build event-driven architectures with real-time data processing, routing events to targets like Lambda functions, and automating workflows.&lt;/p&gt;

&lt;h2&gt;
  
  
  Architecture:
&lt;/h2&gt;

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

&lt;h2&gt;
  
  
  Let’s get down to business!
&lt;/h2&gt;

&lt;p&gt;The next thing is going through the steps from scratch in order to implement our solution. You need not worry about the Python3 code as you only need to copy-paste it.&lt;/p&gt;

&lt;h2&gt;
  
  
  STEP 1:
&lt;/h2&gt;

&lt;p&gt;Create one Windows/Linux instance.&lt;/p&gt;

&lt;h2&gt;
  
  
  STEP 2:
&lt;/h2&gt;

&lt;p&gt;Open the IAM service and create a role to access lambda services.&lt;/p&gt;

&lt;p&gt;• Select AWS services &lt;br&gt;
• Choose lambda use case. &lt;br&gt;
• Click on permission and use two policies: AWSLambdaBasicExecutionRole (allow to use cloudwatch) and AmazonEC2Full Access. Note: You can create your policies, or you can select existing policies &lt;br&gt;
• Provide a tag. &lt;br&gt;
• Provide Role name and role description.&lt;/p&gt;

&lt;h2&gt;
  
  
  STEP 3:
&lt;/h2&gt;

&lt;p&gt;Open Lambda services and create a new lambda function. &lt;/p&gt;

&lt;p&gt;• Provide function name. &lt;br&gt;
• Use Python as a runtime environment. &lt;br&gt;
• Go to permissions and use the created role in Task 2. &lt;br&gt;
• Now basic function code window will appear, and we need to write code for starting and stopping EC2 instances. &lt;/p&gt;

&lt;h2&gt;
  
  
  Code:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#Start instance: 
import boto3 
region = 'us-east-2' 
instances = ['i-0f019ff0664238dcb'] 
ec2 = boto3.client('ec2', region_name=region) 

def lambda_handler(event, context): 
ec2.start_instances(InstanceIds=instances) 
print('starting your instances: ' + str(instances)) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#Stop Instance: 
import boto3 
region = 'us-east-2' 
instances = ['i-0f019ff0664238dcb'] 
ec2 = boto3.client('ec2', region_name=region) 

def lambda_handler(event, context):
ec2.stop_instances(InstanceIds=instances) 
print('stopped your instances: ' + str(instances))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  STEP 4:
&lt;/h2&gt;

&lt;p&gt;Save the code. Select a test event and configure the test event.&lt;/p&gt;

&lt;h2&gt;
  
  
  STEP 5:
&lt;/h2&gt;

&lt;p&gt;Test the EC2 events by clicking on the startEC2 event and stopEC2 event.&lt;/p&gt;

&lt;h2&gt;
  
  
  STEP 6:
&lt;/h2&gt;

&lt;p&gt;Provide the execution details of the lambda function.&lt;/p&gt;

&lt;h2&gt;
  
  
  STEP 7:
&lt;/h2&gt;

&lt;p&gt;Select the event bridge and click on create a rule to trigger the created lambda function. &lt;/p&gt;

&lt;p&gt;• Provide a name and description for the rule. &lt;br&gt;
• Define pattern as an event by providing Cron expression. &lt;br&gt;
• Select targets as Lambda function, provide the name of the function, and copy the JSON text from the event window. &lt;br&gt;
• Create the rule now.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Congratulations! You've successfully Automated a Instance Using AWS Lambda and EventBridge.Automating instance management with AWS Lambda and EventBridge enhances efficiency, reduces costs, and optimizes resource allocation by automating responses to events. This streamlines operations and ensures instances are managed according to specific conditions or schedules.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Hosting a Static Website Using S3 in AWS with Terraform</title>
      <dc:creator>Kousalya S</dc:creator>
      <pubDate>Thu, 27 Jun 2024 18:26:52 +0000</pubDate>
      <link>https://dev.to/kousalya_s_1e656b83b89b93/hosting-a-static-website-using-s3-in-aws-with-terraform-431p</link>
      <guid>https://dev.to/kousalya_s_1e656b83b89b93/hosting-a-static-website-using-s3-in-aws-with-terraform-431p</guid>
      <description>&lt;p&gt;Hello Everyone!!here's a blog post on hosting a static website using Amazon S3 and Terraform.&lt;/p&gt;




&lt;h2&gt;
  
  
  Hosting a Static Website on AWS S3 Using Terraform
&lt;/h2&gt;

&lt;p&gt;Hosting a static website on AWS S3 is a cost-effective and efficient way to make your content accessible to the world. By using Terraform, an infrastructure as code tool, you can automate the setup process, making it repeatable and easy to manage. In this tutorial, we'll walk you through the steps to host a static website on AWS S3 using Terraform.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Amazon S3?
&lt;/h2&gt;

&lt;p&gt;Amazon S3 (Simple Storage Service) is a scalable object storage service provided by AWS. It allows users to store and retrieve any amount of data at any time. S3 is often used for backup, archiving, and hosting static websites due to its high durability, security, and cost-effectiveness.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;AWS Account&lt;/strong&gt;: You need an AWS account to create the necessary resources.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Terraform&lt;/strong&gt;: Install Terraform on your local machine. You can download it from the &lt;a href="https://www.terraform.io/downloads.html"&gt;Terraform website&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AWS CLI&lt;/strong&gt;: Install and configure the AWS CLI with your credentials.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  STEP 1: Setup the Terraform
&lt;/h2&gt;

&lt;p&gt;To set up Terraform, install it from terraform.io, configure AWS CLI, create a main.tf file with your infrastructure code, then run &lt;code&gt;terraform init&lt;/code&gt; and &lt;code&gt;terraform apply&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`terraform {
  required_version = "1.7.4"
  required_providers {
    aws = {
        source = "hashicorp/aws"
        version = "5.40.0"
    }
  }
}
provider "aws" {
  profile = "default"
  region = "ap-south-1"
} `

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  STEP 2: Configuration for S3 Buckets:
&lt;/h2&gt;

&lt;p&gt;Create an S3 bucket in Terraform with &lt;code&gt;aws_s3_bucket&lt;/code&gt;, set &lt;code&gt;bucket&lt;/code&gt; name, &lt;code&gt;acl&lt;/code&gt; to "public-read", and &lt;code&gt;website&lt;/code&gt; configuration. Add a policy with &lt;code&gt;aws_s3_bucket_policy&lt;/code&gt; for public access.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#Create S3 Bucket
resource "aws_s3_bucket" "terraform-demo-43234" {
  bucket = "terraform-demo-43234"
}

#Upload file to S3
resource "aws_s3_object" "terraform_index" {
  bucket = aws_s3_bucket.terraform-demo-43234.id
  key = "index.html"
  source = "index.html"
  content_type = "text/html"
  etag = filemd5("index.html")
}

#S3 Web hosting
resource "aws_s3_bucket_website_configuration" "terraform_hosting" {
  bucket = aws_s3_bucket.terraform-demo-43234.id

  index_document {
    suffix = "index.html"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  step 3: configuration for bucket policy
&lt;/h2&gt;

&lt;p&gt;Create a ‘policy.tf’ file to store the terraform configuration related to the bucket policy for public access.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#S3 public access
resource "aws_s3_bucket_public_access_block" "terraform-demo" {
    bucket = aws_s3_bucket.terraform-demo-43234.id
  block_public_acls = false
  block_public_policy = false
}

#S3 public Read policy
resource "aws_s3_bucket_policy" "open_access" {
  bucket = aws_s3_bucket.terraform-demo-43234.id

  policy = jsonencode({
    Version = "2012-10-17"
    Id      = "Public_access"
    Statement = [
      {
        Sid = "IPAllow"
        Effect = "Allow"
        Principal = "*"
        Action = ["s3:GetObject"]
        Resource = "${aws_s3_bucket.terraform-demo-43234.arn}/*"
      },
    ]
  })
  depends_on = [ aws_s3_bucket_public_access_block.terraform-demo ]
}

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  step 4:Configuration for Output variable
&lt;/h2&gt;

&lt;p&gt;This is an optional step. We are doing this to get a static website URL which we can also get through AWS Console. Create an ‘output.tf’ to print out the URL to access the website.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Website URL
output "website_url" {
  value = "http://${aws_s3_bucket.terraform-demo-43234.bucket}.s3-website.${aws_s3_bucket.terraform-demo-43234.region}.amazonaws.com"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 5: Initialize Terraform
&lt;/h2&gt;

&lt;p&gt;To initialize Terraform , navigate to the directory containing your Terraform configuration files and run &lt;code&gt;terraform init&lt;/code&gt;. This command initializes the environment, downloads necessary plugins, and prepares Terraform to manage your infrastructure according to the configuration defined in &lt;code&gt;main.tf&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 6: Terraform Validate
&lt;/h2&gt;



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

&lt;/div&gt;



&lt;p&gt;Terraform files in your project directory are verified for syntax and configuration using the &lt;code&gt;terraform validate&lt;/code&gt; command. Without actually running the configuration files, it checks them for problems. By doing this, you can make sure that before making any modifications to your infrastructure, your Terraform settings follow the proper syntax and structure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Terraform Plan
&lt;/h2&gt;



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

&lt;/div&gt;



&lt;p&gt;Go to the directory of your project and execute the command &lt;code&gt;terraform plan' to create a Terraform execution plan. By comparing the desired state specified in your configuration files (&lt;/code&gt;main.tf') with the present infrastructure state, Terraform suggests actions (create, update, and remove). Before using &lt;code&gt;terraform apply&lt;/code&gt; to apply changes, review the plan.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 8: Terraform Apply
&lt;/h2&gt;



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

&lt;/div&gt;



&lt;p&gt;To apply Terraform configuration changes, run &lt;code&gt;terraform apply&lt;/code&gt;. Terraform will show a plan of actions to be performed based on your &lt;code&gt;main.tf&lt;/code&gt; file. Confirm with &lt;code&gt;yes&lt;/code&gt; to execute changes, creating or updating resources as specified.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 9: Destroy
&lt;/h2&gt;



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

&lt;/div&gt;



&lt;p&gt;The terraform destroy command in Terraform serves the purpose of tearing down the infrastructure resources that your Terraform configuration currently manages.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Congratulations! You've successfully hosted a static website on AWS S3 using Terraform. This setup is highly scalable, cost-effective, and easy to manage. By using Terraform, you can version control your infrastructure and make deployment a breeze.Happy hosting!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Creating , Modifying , and Destroying an EC2 Instance in AWS with Terraform</title>
      <dc:creator>Kousalya S</dc:creator>
      <pubDate>Thu, 27 Jun 2024 17:12:35 +0000</pubDate>
      <link>https://dev.to/kousalya_s_1e656b83b89b93/creating-modifying-and-destroying-an-ec2-instance-in-aws-with-terraform-mge</link>
      <guid>https://dev.to/kousalya_s_1e656b83b89b93/creating-modifying-and-destroying-an-ec2-instance-in-aws-with-terraform-mge</guid>
      <description>&lt;p&gt;Hi Friends! As part of my internship,We will learn how we can Creating, Modifying, and Destroying an EC2 Instance with Terraform&lt;/p&gt;

&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;Terraform is an open-source infrastructure as code (IaC) tool developed by HashiCorp. It allows you to define, create, and manage infrastructure resources in a declarative way, using a high-level configuration language. With Terraform, you can easily provision, update, and delete infrastructure resources, such as virtual machines, databases, load balancers, and more, across multiple cloud providers or on-premises data centers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before we begin, make sure you have the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;An AWS account.&lt;/li&gt;
&lt;li&gt;AWS CLI configured with your AWS credentials.&lt;/li&gt;
&lt;li&gt;Terraform installed on your machine.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step 1: Setting Up Your Terraform Configuration
&lt;/h2&gt;

&lt;p&gt;First, create a new directory for your Terraform project and navigate into it.Next, create a new file named &lt;code&gt;main.tf&lt;/code&gt; and open it in your favorite text editor. This file will contain the configuration for &lt;br&gt;
your EC2 instance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Configuring AWS Provider
&lt;/h2&gt;

&lt;p&gt;In &lt;code&gt;main.tf&lt;/code&gt;, start by defining the AWS provider. This tells Terraform to use AWS as the provider for your infrastructure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Creating an EC2 Instance
&lt;/h2&gt;

&lt;p&gt;To create an EC2 instance on AWS in the simplest way using Terraform,create a file called main.tf and define a &lt;code&gt;provider&lt;/code&gt; block for AWS in your &lt;code&gt;.tf&lt;/code&gt; file. Add a &lt;code&gt;resource&lt;/code&gt; block for the &lt;code&gt;aws_instance&lt;/code&gt; &lt;br&gt;
specifying the AMI and instance type. Run &lt;code&gt;terraform init&lt;/code&gt;, &lt;code&gt;terraform plan&lt;/code&gt;, and &lt;code&gt;terraform apply&lt;/code&gt; to provision the instance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Initializing Terraform
&lt;/h2&gt;

&lt;p&gt;To initialize Terraform, create a directory for your configuration files. Inside it, create a main configuration file (e.g., &lt;code&gt;main.tf&lt;/code&gt;). Run &lt;code&gt;terraform init&lt;/code&gt; in your terminal within this directory. This command downloads necessary plugins and prepares your working directory for other Terraform commands.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Applying the Configuration
&lt;/h2&gt;

&lt;p&gt;To apply the Terraform configuration, navigate to your project directory in the terminal. Run &lt;code&gt;terraform init&lt;/code&gt; to initialize the project, then use &lt;code&gt;terraform plan&lt;/code&gt; to review the changes.Review the plan and type ‘yes’ to apply the changes. Finally, execute &lt;code&gt;terraform apply&lt;/code&gt; to apply the&lt;br&gt;
configuration and provision the resources. Confirm whenprompted.Terraform will then create the EC2 instance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Modifying the EC2 Instance
&lt;/h2&gt;

&lt;p&gt;If you want to modify the instance (e.g., change the instance type), simply update the &lt;code&gt;main.tf&lt;/code&gt; file. For example, to change the instance type to &lt;code&gt;t2.small&lt;/code&gt;, update the &lt;code&gt;instance_type&lt;/code&gt; . Save the file and &lt;br&gt;
run the following command ‘terraform apply’to apply the changes . Terraform will update the instance to the new configuration.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 7: Destroying the EC2 Instance
&lt;/h3&gt;

&lt;p&gt;When you no longer need the EC2 instance, you can destroy it using Terraform. Run the following command ‘terraform destroy’. Terraform will show you a plan of the resources it will destroy. Review the plan and type &lt;code&gt;yes&lt;/code&gt; to proceed. Terraform will then terminate the EC2 instance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this blog post, we covered the basics of creating, modifying, and destroying an EC2 instance using Terraform. By using Terraform, you can manage your cloud infrastructure in a consistent and repeatable way, making it easier to scale and maintain your environment. Happy Terraforming&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
