AWS Lambda Create a Lambda Function with CloudFromation

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

External

Internal

Resource Types

AWS::Lambda::Function

AWS::Lambda::Function
CreateFunction
 Resources:
   LambdaExecutionRole:
     Type: AWS::IAM::Role
     Properties:
       RoleName: playground-lambda-execution-role
       Path: /service-role/
       AssumeRolePolicyDocument:
         Version: '2012-10-17'
         Statement:
           - Effect: 'Allow'
             Principal:
               Service:
                 - "lambda.amazonaws.com"
             Action:
               - "sts:AssumeRole"
       Policies:
         - PolicyName: 'inline-policy'
           PolicyDocument:
             Version: '2012-10-17'
             Statement:
               - Effect: 'Allow'
                 Action:
                   - 'logs:CreateLogGroup'
                   - 'logs:CreateLogStream'
                   - 'logs:PutLogEvents'
                 Resource:
                   - 'arn:aws:logs:*:*:*'
               - Effect: 'Allow'
                Action:
                  - 'ec2:CreateNetworkInterface'
                  - 'ec2:DescribeNetworkInterfaces'
                  - 'ec2:DeleteNetworkInterface'
                Resource:
                  - '*'
   LambdaExample:
     Type: "AWS::Lambda::Function"
     Properties: 
       [[AWS_Lambda_Concepts#Function_Name|FunctionName]]: my-lambda
       Description: 'Some description'
       [[AWS_Lambda_Concepts#Code|Code]]:
         S3Bucket: a-bucket
         S3Key: a-deployment-package
         # S3ObjectVersion: String
         # ZipFile: String
       [[AWS_Lambda_Concepts#Handler_Code|Handler]]: handler
       [[AWS_Lambda_Concepts#Runtime|Runtime]]: java8
       [[AWS_Lambda_Concepts#Environment_Variables|Environment]]:
         <span id='Variables'></span>Variables:
           MY_ENV_VAR: 'my value'
       [[AWS_Lambda_Concepts#Relationship_to_a_VPC|VpcConfig]]:
         SubnetIds:
           - red-subnet
         SecurityGroupIds:
           - ...
       [[AWS_Lambda_Concepts#Memory_Configuration|MemorySize]]: 128
       [[AWS_Lambda_Concepts#Role|Role]]: !GetAtt LambdaExecutionRole.Arn
       [[AWS_Lambda_Concepts#Timeout|Timeout]]: ''Integer''
       [[AWS_Lambda_Concepts#Concurrent_Execution|ReservedConcurrentExecutions]]: ''Integer''
       [[AWS_Lambda_Concepts#Dead_Letter|DeadLetterConfig]]:
         ''DeadLetterConfig''
       [[AWS_Lambda_Concepts#KMS_Management_Service_Key|KmsKeyArn]]: ''String''
       [[AWS_Lambda_Concepts#Layer|Layers]]:
         - ''String''
       [[AWS_Lambda_Concepts#Tracing|TracingConfig]]:
         ''TracingConfig''
       Tags:
         Resource Tag

CloudFormation Stack Example

https://github.com/ovidiuf/aws-release-pipeline/blob/master/lambda/lambda.yaml

Create a bash Lambda

Publishing a Custom Runtime

Create a Java Lambda

AWS Java Lambda Development