From 16743649fb4c7d27fa25d8e61717756f8b94b980 Mon Sep 17 00:00:00 2001 From: Scott Brenner Date: Sat, 29 Jun 2024 09:48:20 -0700 Subject: [PATCH] Update template.yml --- examples/template.yml | 94 ++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 45 deletions(-) diff --git a/examples/template.yml b/examples/template.yml index 2fef8e0..789b066 100644 --- a/examples/template.yml +++ b/examples/template.yml @@ -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.12. + Runtime: python3.12 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}