AWS Lambda Create a Lambda Function with CloudFromation: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 15: Line 15:
{{External|[https://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html CreateFunction]}}
{{External|[https://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html CreateFunction]}}


<syntaxhighlight lang='yaml'>
  Resources:
  Resources:
   LambdaExecutionRole:
   LambdaExecutionRole:
Line 83: Line 82:
       Tags:
       Tags:
         Resource Tag
         Resource Tag
</syntaxhighlight>


=CloudFormation Stack Example=
=CloudFormation Stack Example=

Revision as of 03:37, 8 April 2019

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: 
      FunctionName: my-lambda
      Description: 'Some description'
      Code:
        S3Bucket: a-bucket
        S3Key: a-deployment-package
        # S3ObjectVersion: String
        # ZipFile: String
      Handler: handler
      Runtime: java8
      Environment:
        Variables:
          MY_ENV_VAR: 'my value'
      VpcConfig:
        SubnetIds:
          - red-subnet
        SecurityGroupIds:
          - ...
      MemorySize: 128
      Role: !GetAtt LambdaExecutionRole.Arn
      Timeout: Integer
      ReservedConcurrentExecutions: Integer
      DeadLetterConfig:
        DeadLetterConfig
      KmsKeyArn: String
      Layers:
        - String
      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