Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update examples/template.yml #403

Merged
merged 2 commits into from
Jun 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 49 additions & 45 deletions examples/template.yml
Original file line number Diff line number Diff line change
@@ -1,80 +1,84 @@
# https://github.com/awslabs/aws-cloudformation-templates/blob/master/community/services/Lambda/LambdaSample.yaml
AWSTemplateFormatVersion: '2010-09-09'
# https://github.com/aws-cloudformation/aws-cloudformation-templates/blob/main/Lambda/LambdaSample.yaml
AWSTemplateFormatVersion: "2010-09-09"

Description: Template for Lambda Sample.

Parameters:
EnvName:
Type: String
Description: Name of an environment. 'dev', 'staging', 'prod' and any name.
Type: String
AllowedPattern: ^.*[^0-9]$
ConstraintDescription: Must end with non-numeric character.

LambdaHandlerPath:
Type: String
Description: Path of a Lambda Handler.
Type: String
AllowedPattern: ^.*[^0-9]$
ConstraintDescription: Must end with non-numeric character.
Outputs:
LambdaRoleARN:
Description: Role for Lambda execution.
Value:
Fn::GetAtt:
- LambdaRole
- Arn
Export:
Name:
Fn::Sub: LambdaRole-${EnvName}
LambdaFunctionName:
Value:
Ref: LambdaFunction
LambdaFunctionARN:
Description: Lambda function ARN.
Value:
Fn::GetAtt:
- LambdaFunction
- Arn
Export:
Name:
Fn::Sub: LambdaARN-${EnvName}

Resources:
LambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName:
Fn::Sub: lambda-role-${EnvName}
RoleName: lambda-role
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Version: 2012-10-17
- lambda.amazonaws.com
Version: "2012-10-17"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AWSLambdaExecute
- arn:aws:iam::aws:policy/AmazonS3FullAccess
- arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess
- arn:aws:iam::aws:policy/AmazonKinesisFullAccess
Path: /

LambdaFunction:
Type: AWS::Lambda::Function
Metadata:
guard:
SuppressedRules:
- LAMBDA_INSIDE_VPC
- LAMBDA_FUNCTION_PUBLIC_ACCESS_PROHIBITED
Properties:
FunctionName:
Fn::Sub: lambda-function-${EnvName}
Description: LambdaFunctioni of nodejs18.x.
Runtime: nodejs18.x
FunctionName: !Sub lambda-function-${EnvName}
Description: LambdaFunction using python3.9.
Runtime: python3.9
Code:
ZipFile:
"exports.handler = function(event, context){\n
var sample = sample;"
Handler: !Ref LambdaHandlerPath
ZipFile: |
import json

def lambda_handler(event, context):
print(json.dumps(event))
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
Handler: !Sub ${LambdaHandlerPath}
MemorySize: 128
Timeout: 10
Role:
Fn::GetAtt:
- LambdaRole
- Arn
Role: !GetAtt LambdaRole.Arn
Environment:
Variables:
ENV:
Fn::Sub: ${EnvName}
ENV: !Ref EnvName
TZ: UTC

Outputs:
LambdaRoleARN:
Description: Role for Lambda execution.
Value: !GetAtt LambdaRole.Arn
Export:
Name: LambdaRole

LambdaFunctionName:
Value: !Ref LambdaFunction

LambdaFunctionARN:
Description: Lambda function ARN.
Value: !GetAtt LambdaFunction.Arn
Export:
Name: !Sub LambdaARN-${EnvName}
Loading