<?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: Kaviya Kathirvelu</title>
    <description>The latest articles on DEV Community by Kaviya Kathirvelu (@kaviya_kathirvelu_0505).</description>
    <link>https://dev.to/kaviya_kathirvelu_0505</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%2F1682065%2F190c4f7d-a3b0-4167-9a36-277cace8048e.png</url>
      <title>DEV Community: Kaviya Kathirvelu</title>
      <link>https://dev.to/kaviya_kathirvelu_0505</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kaviya_kathirvelu_0505"/>
    <language>en</language>
    <item>
      <title>Building a Serverless CRUD API with AWS: A Comprehensive Guide</title>
      <dc:creator>Kaviya Kathirvelu</dc:creator>
      <pubDate>Tue, 09 Jul 2024 06:39:14 +0000</pubDate>
      <link>https://dev.to/kaviya_kathirvelu_0505/building-a-serverless-crud-api-with-aws-a-comprehensive-guide-ljm</link>
      <guid>https://dev.to/kaviya_kathirvelu_0505/building-a-serverless-crud-api-with-aws-a-comprehensive-guide-ljm</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the era of cloud computing, serverless architectures have become a game-changer, allowing developers to build and deploy applications without worrying about the underlying infrastructure. AWS offers a powerful suite of services that make it easy to create serverless applications. In this blog, we'll walk you through building a serverless CRUD (Create, Read, Update, Delete) API using AWS Lambda, API Gateway, IAM, and DynamoDB.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Choose Serverless?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Serverless computing offers several advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Scalability:&lt;br&gt;
Automatically scales with the demand.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cost-Efficiency:&lt;br&gt;
Pay only for what you use.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reduced Operational Overhead:&lt;br&gt;
Focus on code rather than infrastructure.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;High Availability:&lt;br&gt;
Built-in redundancy and fault tolerance.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Components of Our Serverless CRUD API&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;API Gateway:&lt;br&gt;
Acts as the entry point for your API.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;AWS Lambda:&lt;br&gt;
Executes your business logic.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;IAM:&lt;br&gt;
Manages access and permissions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;DynamoDB:&lt;br&gt;
A NoSQL database for storing your data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Postman software:&lt;br&gt;
A software that is used to write code and send requests to the API Gateway&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step-by-Step Guide&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Set Up DynamoDB&lt;br&gt;
Create a DynamoDB table named product-inventory with productid as the partition key.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create Lambda Functions&lt;br&gt;
Create Lambda functions for each CRUD operation. Here's an example of a Lambda function for handling all CRUD operations:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deploy Lambda Functions&lt;br&gt;
Deploy your Lambda functions using the AWS Management Console or AWS CLI.&lt;br&gt;
Here is a sample code:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const AWS = require('aws-sdk');
AWS.config.update( {
  region: 'us-east-1'
});
const dynamodb = new AWS.DynamoDB.DocumentClient();
const dynamodbTableName = 'product-inventory';
const healthPath = '/health';
const productPath = '/product';
const productsPath = '/products';

exports.handler = async function(event) {
  console.log('Request event: ', event);
  let response;
  switch(true) {
    case event.httpMethod === 'GET' &amp;amp;&amp;amp; event.path === healthPath:
      response = buildResponse(200);
      break;
    case event.httpMethod === 'GET' &amp;amp;&amp;amp; event.path === productPath:
      response = await getProduct(event.queryStringParameters.productid);
      break;
    case event.httpMethod === 'GET' &amp;amp;&amp;amp; event.path === productsPath:
      response = await getProducts();
      break;
    case event.httpMethod === 'POST' &amp;amp;&amp;amp; event.path === productPath:
      response = await saveProduct(JSON.parse(event.body));
      break;
    case event.httpMethod === 'PATCH' &amp;amp;&amp;amp; event.path === productPath:
      const requestBody = JSON.parse(event.body);
      response = await modifyProduct(requestBody.productid, requestBody.updateKey, requestBody.updateValue);
      break;
    case event.httpMethod === 'DELETE' &amp;amp;&amp;amp; event.path === productPath:
      response = await deleteProduct(JSON.parse(event.body).productid);
      break;
    default:
      response = buildResponse(404, '404 Not Found');
  }
  return response;
}

async function getProduct(productid) {
  const params = {
    TableName: dynamodbTableName,
    Key: {
      'productid': productid
    }
  }
  return await dynamodb.get(params).promise().then((response) =&amp;gt; {
    return buildResponse(200, response.Item);
  }, (error) =&amp;gt; {
    console.error('Do your custom error handling here. I am just gonna log it: ', error);
  });
}

async function getProducts() {
  const params = {
    TableName: dynamodbTableName
  }
  const allProducts = await scanDynamoRecords(params, []);
  const body = {
    products: allProducts
  }
  return buildResponse(200, body);
}

async function scanDynamoRecords(scanParams, itemArray) {
  try {
    const dynamoData = await dynamodb.scan(scanParams).promise();
    itemArray = itemArray.concat(dynamoData.Items);
    if (dynamoData.LastEvaluatedKey) {
      scanParams.ExclusiveStartkey = dynamoData.LastEvaluatedKey;
      return await scanDynamoRecords(scanParams, itemArray);
    }
    return itemArray;
  } catch(error) {
    console.error('Do your custom error handling here. I am just gonna log it: ', error);
  }
}

async function saveProduct(requestBody) {
  const params = {
    TableName: dynamodbTableName,
    Item: requestBody
  }
  return await dynamodb.put(params).promise().then(() =&amp;gt; {
    const body = {
      Operation: 'SAVE',
      Message: 'SUCCESS',
      Item: requestBody
    }
    return buildResponse(200, body);
  }, (error) =&amp;gt; {
    console.error('Do your custom error handling here. I am just gonna log it: ', error);
  })
}

async function modifyProduct(productid, updateKey, updateValue) {
  const params = {
    TableName: dynamodbTableName,
    Key: {
      'productid': productid
    },
    UpdateExpression: `set ${updateKey} = :value`,
    ExpressionAttributeValues: {
      ':value': updateValue
    },
    ReturnValues: 'UPDATED_NEW'
  }
  return await dynamodb.update(params).promise().then((response) =&amp;gt; {
    const body = {
      Operation: 'UPDATE',
      Message: 'SUCCESS',
      UpdatedAttributes: response
    }
    return buildResponse(200, body);
  }, (error) =&amp;gt; {
    console.error('Do your custom error handling here. I am just gonna log it: ', error);
  })
}

async function deleteProduct(productid) {
  const params = {
    TableName: dynamodbTableName,
    Key: {
      'productid': productid
    },
    ReturnValues: 'ALL_OLD'
  }
  return await dynamodb.delete(params).promise().then((response) =&amp;gt; {
    const body = {
      Operation: 'DELETE',
      Message: 'SUCCESS',
      Item: response
    }
    return buildResponse(200, body);
  }, (error) =&amp;gt; {
    console.error('Do your custom error handling here. I am just gonna log it: ', error);
  })
}

function buildResponse(statusCode, body) {
  return {
    statusCode: statusCode,
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(body)
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Set Up API Gateway
Create an API:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Choose REST API.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set up methods (GET, POST, PATCH, DELETE) for your resources (/health, /product, /products).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Integrate each method with the respective Lambda function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enable CORS and enable proxy for the resources&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configure CORS settings for each method.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deploy the API:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a new deployment stage (e.g., dev, prod).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Configure IAM Roles&lt;br&gt;
Ensure your Lambda functions have the necessary permissions to interact with DynamoDB. Create an IAM role with policies that allow dynamodb to perform actions on your table.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Testing the API&lt;br&gt;
Use tools like Postman or CURL to test your API endpoints. Ensure each CRUD operation works as expected:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;GET /health: Check API health.&lt;br&gt;
GET /product?productid=10001: Retrieve a specific product.&lt;br&gt;
GET /products: Retrieve all products.&lt;br&gt;
POST /product: Create a new product.&lt;br&gt;
PATCH /product: Update an existing product.&lt;br&gt;
DELETE /product: Delete a product.&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%2Fa78hwfg779fgxdxwxub5.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%2Fa78hwfg779fgxdxwxub5.png" alt="Image description" width="800" height="447"&gt;&lt;/a&gt;&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%2Fnni1e6cwu2ve6rpcff4a.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%2Fnni1e6cwu2ve6rpcff4a.png" alt="Image description" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benefits of Using Serverless CRUD API&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Scalability: Automatically scales with demand.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cost-Efficiency: Pay only for what you use.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reduced Operational Overhead: No need to manage servers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;High Availability: Built-in redundancy and fault tolerance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Security: Fine-grained access control with IAM.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Building a serverless CRUD API using AWS Lambda, API Gateway, IAM, and DynamoDB is an excellent choice for scalable, cost-effective, and secure backend solutions. With the steps outlined in this blog, you can quickly set up your own serverless API and start leveraging the power of AWS for your applications. &lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>devops</category>
      <category>aws</category>
      <category>cloudcomputing</category>
      <category>serverless</category>
    </item>
    <item>
      <title>Creating an EC2 Instance and Connecting via SSH with IAM User</title>
      <dc:creator>Kaviya Kathirvelu</dc:creator>
      <pubDate>Fri, 28 Jun 2024 01:45:41 +0000</pubDate>
      <link>https://dev.to/kaviya_kathirvelu_0505/creating-an-ec2-instance-and-connecting-via-ssh-with-iam-user-5c5e</link>
      <guid>https://dev.to/kaviya_kathirvelu_0505/creating-an-ec2-instance-and-connecting-via-ssh-with-iam-user-5c5e</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Creating and managing cloud infrastructure can be streamlined with AWS and Terraform. This blog post will guide you through the process of creating an EC2 instance and an IAM user using the AWS Management Console, and then connecting to the instance via SSH.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;An AWS account.&lt;/li&gt;
&lt;li&gt;Basic understanding of AWS services and SSH.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; &lt;strong&gt;Creating an EC2 Instance in AWS Management Console&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Log in to the AWS Management Console.&lt;/li&gt;
&lt;li&gt;Navigate to the EC2 Dashboard:
  Click on "Services" in the top menu and select "EC2" under the
  "Compute" section.&lt;/li&gt;
&lt;li&gt;Launch an Instance:
  Click the "Launch Instance" button.&lt;/li&gt;
&lt;li&gt;Select an Amazon Machine Image (AMI) of your choice.&lt;/li&gt;
&lt;li&gt;Choose an instance type (e.g., t2.micro for free tier eligibility).&lt;/li&gt;
&lt;li&gt;Configure the instance details as needed.&lt;/li&gt;
&lt;li&gt;Add storage as required.&lt;/li&gt;
&lt;li&gt;Add tags to help identify your instance.&lt;/li&gt;
&lt;li&gt;Configure the security group to allow SSH access (port 22).&lt;/li&gt;
&lt;li&gt;Review and launch the instance.&lt;/li&gt;
&lt;li&gt;Download the Key Pair:
   When prompted, create a new key pair or use an existing one.
   Download the key pair file (e.g., my-key-pair.pem) and save it
   securely.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt;** Creating an IAM User in AWS Management Console**&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Navigate to the IAM Dashboard:
  Click on "Services" in the top menu and select "IAM" under the 
  "Security, Identity, &amp;amp; Compliance" section.&lt;/li&gt;
&lt;li&gt;Create a New User:
  Click the "Add user" button.
  Enter a username (e.g., example-user).
  Select the "Programmatic access" checkbox to provide access via the 
   AWS CLI, SDKs, etc.&lt;/li&gt;
&lt;li&gt;Set Permissions:
  Attach existing policies directly or create a new policy to grant 
  necessary permissions.&lt;/li&gt;
&lt;li&gt;Review and Create User:
  Review the settings and click "Create user."
  Download the access key ID and secret access key, as you will not 
   be able to view them again.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; &lt;strong&gt;Connecting to the EC2 Instance via SSH&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Locate the Public IP Address:
  In the EC2 Dashboard, select your instance.
  Note the public IPv4 address from the instance details.&lt;/li&gt;
&lt;li&gt;Set Permissions on the Key Pair File:
  Open your terminal and navigate to the directory containing the key 
  pair file.&lt;/li&gt;
&lt;li&gt;Run the following command to set the correct permissions:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod 400 my-key-pair.pem
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Connect to the Instance:&lt;/p&gt;

&lt;p&gt;Use the following SSH command to connect to your instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh -i "my-key-pair.pem" ec2-user@&amp;lt;your_instance_public_ip&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace  with the public IP address of your instance.&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%2Fe8wwd3tm1sxstbfvy94x.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%2Fe8wwd3tm1sxstbfvy94x.png" alt="Image description" width="" height=""&gt;&lt;/a&gt;&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%2Fswz0bvhpscjtm4u03low.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%2Fswz0bvhpscjtm4u03low.png" alt="Image description" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You've successfully created an EC2 instance and an IAM user using the AWS Management Console and connected to the instance via SSH. This process highlights the basic steps to get started with AWS EC2 and IAM, laying the groundwork for more complex configurations and automations.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Building a Static Website with Terraform: Step-by-Step Guide</title>
      <dc:creator>Kaviya Kathirvelu</dc:creator>
      <pubDate>Tue, 25 Jun 2024 14:57:17 +0000</pubDate>
      <link>https://dev.to/kaviya_kathirvelu_0505/building-a-static-website-with-terraform-step-by-step-guide-38c6</link>
      <guid>https://dev.to/kaviya_kathirvelu_0505/building-a-static-website-with-terraform-step-by-step-guide-38c6</guid>
      <description>&lt;p&gt;Creating and hosting a static website has never been easier with the power of Infrastructure as Code (IaC) and cloud services. In this guide, we'll walk you through setting up a static website using Terraform to manage AWS resources. You'll learn how to automate the creation of an S3 bucket, configure it for static website hosting, deploy your website files, and some additional considerations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before we start, ensure you have the following:&lt;br&gt;
• An AWS account.&lt;br&gt;
• AWS CLI installed and configured with appropriate permissions.&lt;br&gt;
• Terraform installed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Initialize Your Project&lt;/p&gt;

&lt;p&gt;Create a new directory for your Terraform project and navigate to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir my-static-website
&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;cd my-static-website
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Define Your Terraform Configuration&lt;/p&gt;

&lt;p&gt;Create a file named terraform.tf and define your provider configuration:&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 = "&amp;gt;= 1.8.5"
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~&amp;gt; 5.40.0"
    }
  }
}

provider "aws" {
  profile = "default"
  region  = "ap-south-1"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configuration sets up Terraform to use the AWS provider, specifying your AWS profile and region.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Create the S3 Bucket&lt;/p&gt;

&lt;p&gt;Create a file named bucket.tf to define your S3 bucket and its configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource "aws_s3_bucket" "terraform_demo_43234" {
  bucket = "terraform-demo-43234-unique-id" # Ensure this bucket name is unique
}

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")
}

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;p&gt;This defines an S3 bucket and uploads an index.html file to it, configuring the bucket for static website hosting.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Set Bucket Policies&lt;/p&gt;

&lt;p&gt;Create a file named policy.tf to define your S3 bucket policies 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;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
}

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;p&gt;This ensures your bucket's objects are publicly accessible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Output the Website URL&lt;/p&gt;

&lt;p&gt;Create a file named output.tf to output your website's URL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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;p&gt;This outputs the URL of your hosted static website after deployment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; Deploy Your Static Website&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt;  Initialize Terraform:&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;p&gt;This command prepares your working directory for other Terraform commands.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt;  Apply the Configuration:&lt;br&gt;
&lt;/p&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;Review the changes and confirm with yes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt;  Access Your Website:&lt;/p&gt;

&lt;p&gt;After the apply process completes, Terraform will output your website's URL. Visit this URL to see your static website live.&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%2F7ac92lkf5z7ntmguq23m.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%2F7ac92lkf5z7ntmguq23m.png" alt="Image description" width="800" height="365"&gt;&lt;/a&gt;&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%2Flr7yczhtj8goesruc8sq.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%2Flr7yczhtj8goesruc8sq.png" alt="Image description" width="800" height="372"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Additional Considerations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;• Custom Domain: To use a custom domain for your static website, you can set up Route 53 for DNS management and CloudFront for CDN and SSL/TLS termination.&lt;/p&gt;

&lt;p&gt;• Versioning and Backup: Enable versioning on your S3 bucket to maintain backups of your files. This helps in case of accidental deletion or modification.&lt;/p&gt;

&lt;p&gt;• Security: Review and implement appropriate security measures, such as bucket policies and IAM roles, to restrict access and protect your resources.&lt;/p&gt;

&lt;p&gt;• Monitoring and Logging: Set up S3 access logging and CloudWatch alarms to monitor and manage your static website's performance and availability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Congratulations! You've successfully deployed a static website using Terraform on AWS. By leveraging Infrastructure as Code, you can manage your resources efficiently and ensure consistency across deployments. This approach not only saves time but also enhances scalability and maintainability for your projects.&lt;/p&gt;

&lt;p&gt;Feel free to explore more Terraform resources and customize your setup further. Happy coding!&lt;/p&gt;

</description>
      <category>aws</category>
      <category>cloudcomputing</category>
      <category>awscloudclubs</category>
    </item>
  </channel>
</rss>
