Created
February 3, 2025 13:33
-
-
Save husobee/5721810acdd1c1ecf0caab6565302a6a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: "2010-09-09" | |
Description: "CloudFormation Stack with Lambda and IAM Role" | |
Resources: | |
MyLambdaRole: | |
Type: "AWS::IAM::Role" | |
Properties: | |
RoleName: "MyLambdaExecutionRole" | |
AssumeRolePolicyDocument: | |
Version: "2012-10-17" | |
Statement: | |
- Effect: "Allow" | |
Principal: | |
Service: "lambda.amazonaws.com" | |
Action: "sts:AssumeRole" | |
Policies: | |
- PolicyName: "LambdaBasicExecution" | |
PolicyDocument: | |
Version: "2012-10-17" | |
Statement: | |
- Effect: "Allow" | |
Action: | |
- "logs:CreateLogGroup" | |
- "logs:CreateLogStream" | |
- "logs:PutLogEvents" | |
Resource: "*" | |
MyLambdaFunction: | |
Type: "AWS::Lambda::Function" | |
Properties: | |
FunctionName: "MyLambdaFunction" | |
Runtime: "python3.8" | |
Handler: "index.handler" | |
Role: !GetAtt MyLambdaRole.Arn | |
Code: | |
ZipFile: | | |
def handler(event, context): | |
return {"message": "Hello from Lambda!"} | |
AWSTemplateFormatVersion: "2010-09-09" | |
Description: "Updated Stack - Modified IAM Role" | |
Resources: | |
MyLambdaRole: | |
Type: "AWS::IAM::Role" | |
Properties: | |
RoleName: "MyLambdaExecutionRole" | |
AssumeRolePolicyDocument: | |
Version: "2012-10-17" | |
Statement: | |
- Effect: "Allow" | |
Principal: | |
Service: "lambda.amazonaws.com" | |
Action: "sts:AssumeRole" | |
Policies: | |
- PolicyName: "LambdaRestrictedExecution" | |
PolicyDocument: | |
Version: "2012-10-17" | |
Statement: | |
- Effect: "Deny" | |
Action: | |
- "logs:CreateLogGroup" | |
- "logs:CreateLogStream" | |
- "logs:PutLogEvents" | |
Resource: "*" | |
MyLambdaFunction: | |
Type: "AWS::Lambda::Function" | |
Properties: | |
FunctionName: "MyLambdaFunction" | |
Runtime: "python3.8" | |
Handler: "index.handler" | |
Role: !GetAtt MyLambdaRole.Arn | |
Code: | |
ZipFile: | | |
def handler(event, context): | |
return {"message": "Hello from Lambda!"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment