Skip to main content

Command Palette

Search for a command to run...

AWS Day 48: Automating Infrastructure Deployment with AWS CloudFormation

Updated
2 min readView as Markdown
AWS Day 48: Automating Infrastructure Deployment with AWS CloudFormation
A

"I'm a 3rd-year Computer Engineering student at Marwadi University with skills in C++, web development (MERN stack), and DevOps tools like Kubernetes. I contribute to open-source projects and share tech knowledge on GitHub and LinkedIn. I'm learning cloud technologies and app deployment. As an Internshala Student Partner, I help others find jobs and courses." now currently focusing on #90DaysOfDevops

Continuing my KodeKloud 100 Days of Cloud journey, Day 48 focused on using AWS CloudFormation to automate Lambda deployment.

Instead of creating the Lambda function and IAM role manually from the AWS Console, I defined the infrastructure as code in a CloudFormation template. This makes the deployment repeatable, consistent, and easier to manage.

What I Built

For this lab, I created:

  • CloudFormation stack: xfusion-lambda-app

  • Lambda function: xfusion-lambda

  • IAM role: lambda_execution_role

  • Runtime: Python 3.12

  • Lambda response status code: 200

  • Response body: Welcome to KKE AWS Labs!

Step 1: Create the CloudFormation Template

I created the template on the AWS client host:

/root/xfusion-lambda.yml

The template defines both the IAM role and Lambda function, so CloudFormation can create the required resources automatically.

One important part is the Lambda execution role:

RoleName: lambda_execution_role

The role uses the AWS managed policy:

AWSLambdaBasicExecutionRole

which allows Lambda to write its execution logs to CloudWatch.

Step 2: Configure the Lambda Function

The Lambda function was configured with:

FunctionName: xfusion-lambda
Runtime: python3.12
Handler: index.lambda_handler

The function returns a successful HTTP-style response:

return {
    "statusCode": 200,
    "body": "Welcome to KKE AWS Labs!"
}

This satisfies the requirement for both the 200 status code and the expected response body.

Step 3: Deploy the CloudFormation Stack

After creating the YAML template, I deployed it using AWS CLI:

aws cloudformation create-stack --stack-name xfusion-lambda-app --template-body file:///root/xfusion-lambda.yml --capabilities CAPABILITY_NAMED_IAM

The CAPABILITY_NAMED_IAM option is required because the template creates a named IAM role.

CloudFormation then handled the creation of the IAM role and Lambda function.

Step 4: Verify the Lambda Function

After the stack was created successfully, I invoked the Lambda function:

aws lambda invoke \
  --function-name xfusion-lambda \
  --payload '{}' \
  response.json

The invocation returned:

{
    "StatusCode": 200,
    "ExecutedVersion": "$LATEST"
}

This confirmed that the Lambda function was successfully deployed and executed.

What I Learned

The main takeaway from this lab was how AWS CloudFormation turns infrastructure into code.

Conclusion

AWS Day 48 was a practical introduction to Infrastructure as Code with AWS CloudFormation.

Creating the Lambda function through CloudFormation helped me understand how AWS resources can be defined, deployed, and managed without relying entirely on the AWS Console.

Another step completed in my AWS, Cloud, and DevOps learning journey.

100 Days Of Cloud (AWS)

Part 1 of 40

This series documents my 100 Days of Cloud journey with AWS using KodeKloud. Each blog covers one daily task with hands-on practice, simple explanations, and real learning for beginners and cloud aspirants.

Up next

AWS Day 47: Integrating AWS SQS and SNS for Reliable Messaging

Continuing my KodeKloud 100 Days of Cloud journey, Day 47 focused on building a priority-based messaging system using Amazon SNS, Amazon SQS, AWS Lambda, and CloudFormation. The goal was simple: messa

More from this blog

A

Anand Raval

144 posts

I'm Anand Raval, a Cloud & DevOps Engineer with AWS Solutions Architect Associate (SAA-C03), Certified Kubernetes Administrator (CKA), and Azure Fundamentals (AZ-900) certifications. This blog covers AWS, Kubernetes, Terraform, CI/CD, cloud architecture, automation, cost optimization, troubleshooting guides, and hands-on DevOps projects.