
CloudFormation is used as a way to create Amazon Web Services (AWS) resources from template files, such as a JSON or YAML file. In this way, CloudFormation is Infrastructure as Code (IAC).
Since this is just a Getting Started article, let's keep it simple. We'll use CloudFormation to create a Lambda Function named "poc-lambda-function" using the following YAML.
Resources:
LambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName: poc-lambda-role
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Version: "2012-10-17"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AWSLambdaExecute
- arn:aws:iam::aws:policy/AmazonS3FullAccess
Path: /
Function:
Type: AWS::Lambda::Function
Properties:
FunctionName: poc-lambda-function
Description: my poc-lambda-function
Runtime: python3.12
Code:
ZipFile: |
import json
def lambda_handler(event, context):
print("Received event: " + json.dumps(event, indent=2))
return ""
Handler: poc-lambda-function.py
MemorySize: 128
Timeout: 10
Role: !GetAtt LambdaRole.Arn
In the AWS Console, let's go to CloudFormation and select Create Stack. Let's go with all of the defaults except we are going to use our YAML file as the template.
Then select Next, Next, Next, Submit. Give it a few moments to deploy, and the deploy should show CREATE_COMPLETE.
And if we go over to the Lambda console, we should see our Lambda Function.
And over at the IAM console, we should see the role.
If you delete the stack, the Lambda Function and IAM Role will be deleted.
Did you find this article helpful?
If so, consider buying me a coffee over at