Skip to content

Instantly share code, notes, and snippets.

@CodeBabel
Last active January 7, 2025 21:27
Show Gist options
  • Select an option

  • Save CodeBabel/eab082667728f6db40751f3105694ff8 to your computer and use it in GitHub Desktop.

Select an option

Save CodeBabel/eab082667728f6db40751f3105694ff8 to your computer and use it in GitHub Desktop.
AWS IaC Generator Lambda templates
---
Metadata:
AWSToolsMetrics:
IaC_Generator: "arn:aws:cloudformation:us-east-2:xxxxxxxxxxx:generatedTemplate/3b097fe9-4597-4737-93eb-bc80f6792da2"
Parameters:
LambdaFunction00MyIACGenFunction00TqvZ3CodeSourceKMSKeyArnQL3yK:
NoEcho: "true"
Type: "String"
Description: "Value of write only property Code/SourceKMSKeyArn of resource LambdaFunction00MyIACGenFunction00TqvZ3."
LambdaFunction00MyIACGenFunction00TqvZ3CodeS3KeyKVUxG:
NoEcho: "true"
Type: "String"
Description: "The Amazon S3 key of the deployment package."
LambdaFunction00MyIACGenFunction00TqvZ3CodeS3ObjectVersionzaW72:
NoEcho: "true"
Type: "String"
Description: "For versioned objects, the version of the deployment package object\
\ to use."
LambdaFunction00MyIACGenFunction00TqvZ3CodeS3BucketUkUOL:
NoEcho: "true"
Type: "String"
Description: "An Amazon S3 bucket in the same AWS-Region as your function. The\
\ bucket can be in a different AWS-account."
LambdaFunction00MyIACGenFunction00TqvZ3CodeImageUriGlqrD:
NoEcho: "true"
Type: "String"
Description: "URI of a [container image](https://docs.aws.amazon.com/lambda/latest/dg/lambda-images.html)\
\ in the Amazon ECR registry."
LambdaFunction00MyIACGenFunction00TqvZ3CodeZipFileoQJNX:
Type: "String"
Description: "(Node.js and Python) The source code of your Lambda function. If\
\ you include your function source inline with this parameter, CFN places it\
\ in a file named ``index`` and zips it to create a [deployment package](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-package.html).\
\ This zip file cannot exceed 4MB. For the ``Handler`` property, the first part\
\ of the handler identifier must be ``index``. For example, ``index.handler``.\n\
\ For JSON, you must escape quotes and special characters such as newline (``\\\
n``) with a backslash.\n If you specify a function that interacts with an AWS\
\ CloudFormation custom resource, you don't have to write your own functions\
\ to send responses to the custom resource that invoked the function. AWS CloudFormation\
\ provides a response module ([cfn-response](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-lambda-function-code-cfnresponsemodule.html))\
\ that simplifies sending responses. See [Using Lambda with CloudFormation](https://docs.aws.amazon.com/lambda/latest/dg/services-cloudformation.html)\
\ for details."
Default: |
import json
print('Loading function')
def lambda_handler(event, context):
#print("Received event: " + json.dumps(event, indent=2))
print("value1 = " + event['key1'])
print("value2 = " + event['key2'])
print("value3 = " + event['key3'])
return event['key1'] # Echo back the first key value
#raise Exception('Something went wrong')
Resources:
LambdaFunction00MyIACGenFunction00TqvZ3:
UpdateReplacePolicy: "Retain"
Type: "AWS::Lambda::Function"
DeletionPolicy: "Retain"
Properties:
MemorySize: 128
Description: "A starter AWS Lambda function."
TracingConfig:
Mode: "PassThrough"
Timeout: 3
RuntimeManagementConfig:
UpdateRuntimeOn: "Auto"
Handler: "lambda_function.lambda_handler"
Code:
ZipFile:
Ref: "LambdaFunction00MyIACGenFunction00TqvZ3CodeZipFileoQJNX"
Role:
Fn::GetAtt:
- "IAMRole00lambdarolerole00SRPs2"
- "Arn"
FileSystemConfigs: []
FunctionName: "MyIACGenFunction"
Runtime: "python3.10"
PackageType: "Zip"
LoggingConfig:
LogFormat: "Text"
LogGroup: "/aws/lambda/MyIACGenFunction"
RecursiveLoop: "Terminate"
EphemeralStorage:
Size: 512
Tags:
- Value: "hello-world-python"
Key: "lambda-console:blueprint"
Architectures:
- "x86_64"
IAMRole00lambdarolerole00SRPs2:
UpdateReplacePolicy: "Retain"
Type: "AWS::IAM::Role"
DeletionPolicy: "Retain"
Properties:
Path: "/"
MaxSessionDuration: 3600
RoleName: "lambdarole-role"
Description: "Allows Lambda functions to call AWS services on your behalf."
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Action: "sts:AssumeRole"
Effect: "Allow"
Principal:
Service: "lambda.amazonaws.com"
---
Metadata:
AWSToolsMetrics:
IaC_Generator: "arn:aws:cloudformation:us-east-2:xxxxxxxxxxx:generatedTemplate/3b097fe9-4597-4737-93eb-bc80f6792da2"
Parameters:
LambdaFunction00MyIACGenFunction00TqvZ3CodeSourceKMSKeyArnQL3yK:
NoEcho: "true"
Type: "String"
Description: "Value of write only property Code/SourceKMSKeyArn of resource LambdaFunction00MyIACGenFunction00TqvZ3."
LambdaFunction00MyIACGenFunction00TqvZ3CodeS3KeyKVUxG:
NoEcho: "true"
Type: "String"
Description: "The Amazon S3 key of the deployment package."
LambdaFunction00MyIACGenFunction00TqvZ3CodeZipFileoQJNX:
NoEcho: "true"
Type: "String"
Description: "(Node.js and Python) The source code of your Lambda function. If\
\ you include your function source inline with this parameter, CFN places it\
\ in a file named ``index`` and zips it to create a [deployment package](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-package.html).\
\ This zip file cannot exceed 4MB. For the ``Handler`` property, the first part\
\ of the handler identifier must be ``index``. For example, ``index.handler``.\n\
\ For JSON, you must escape quotes and special characters such as newline (``\\\
n``) with a backslash.\n If you specify a function that interacts with an AWS\
\ CloudFormation custom resource, you don't have to write your own functions\
\ to send responses to the custom resource that invoked the function. AWS CloudFormation\
\ provides a response module ([cfn-response](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-lambda-function-code-cfnresponsemodule.html))\
\ that simplifies sending responses. See [Using Lambda with CloudFormation](https://docs.aws.amazon.com/lambda/latest/dg/services-cloudformation.html)\
\ for details."
LambdaFunction00MyIACGenFunction00TqvZ3CodeS3ObjectVersionzaW72:
NoEcho: "true"
Type: "String"
Description: "For versioned objects, the version of the deployment package object\
\ to use."
LambdaFunction00MyIACGenFunction00TqvZ3CodeS3BucketUkUOL:
NoEcho: "true"
Type: "String"
Description: "An Amazon S3 bucket in the same AWS-Region as your function. The\
\ bucket can be in a different AWS-account."
LambdaFunction00MyIACGenFunction00TqvZ3CodeImageUriGlqrD:
NoEcho: "true"
Type: "String"
Description: "URI of a [container image](https://docs.aws.amazon.com/lambda/latest/dg/lambda-images.html)\
\ in the Amazon ECR registry."
Resources:
LambdaFunction00MyIACGenFunction00TqvZ3:
UpdateReplacePolicy: "Retain"
Type: "AWS::Lambda::Function"
DeletionPolicy: "Retain"
Properties:
MemorySize: 128
Description: "A starter AWS Lambda function."
TracingConfig:
Mode: "PassThrough"
Timeout: 3
RuntimeManagementConfig:
UpdateRuntimeOn: "Auto"
Handler: "lambda_function.lambda_handler"
Code:
SourceKMSKeyArn:
Ref: "LambdaFunction00MyIACGenFunction00TqvZ3CodeSourceKMSKeyArnQL3yK"
S3ObjectVersion:
Ref: "LambdaFunction00MyIACGenFunction00TqvZ3CodeS3ObjectVersionzaW72"
S3Bucket:
Ref: "LambdaFunction00MyIACGenFunction00TqvZ3CodeS3BucketUkUOL"
ZipFile:
Ref: "LambdaFunction00MyIACGenFunction00TqvZ3CodeZipFileoQJNX"
ImageUri:
Ref: "LambdaFunction00MyIACGenFunction00TqvZ3CodeImageUriGlqrD"
S3Key:
Ref: "LambdaFunction00MyIACGenFunction00TqvZ3CodeS3KeyKVUxG"
Role:
Fn::GetAtt:
- "IAMRole00lambdarolerole00SRPs2"
- "Arn"
FileSystemConfigs: []
FunctionName: "MyIACGenFunction"
Runtime: "python3.10"
PackageType: "Zip"
LoggingConfig:
LogFormat: "Text"
LogGroup: "/aws/lambda/MyIACGenFunction"
RecursiveLoop: "Terminate"
EphemeralStorage:
Size: 512
Tags:
- Value: "hello-world-python"
Key: "lambda-console:blueprint"
Architectures:
- "x86_64"
IAMRole00lambdarolerole00SRPs2:
UpdateReplacePolicy: "Retain"
Type: "AWS::IAM::Role"
DeletionPolicy: "Retain"
Properties:
Path: "/"
MaxSessionDuration: 3600
RoleName: "lambdarole-role"
Description: "Allows Lambda functions to call AWS services on your behalf."
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Action: "sts:AssumeRole"
Effect: "Allow"
Principal:
Service: "lambda.amazonaws.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment