shantanuo
shantanuo

Reputation: 32296

Deploy lambda function inline

I have a python function that I can deploy through S3 bucket. But it is possible to deploy a function "inline"...

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html

But I do not see any clear instructions about how to do this. I do not want to use S3 bucket.

Upvotes: 5

Views: 10567

Answers (2)

jens walter
jens walter

Reputation: 14029

You can deploy an AWS Lambda function inline within a CloudFormation template through the following YAML syntax.

  LambdaFunction:
    Type: AWS::Lambda::Function
    Properties:
      Code:
        ZipFile: >
          def handler(event, context):
            print('hello from lambda')
      Handler: index.handler
      Role:
        Fn::GetAtt: [ LambdaRole , "Arn" ]
      Runtime: python3.6
      Timeout: 60

Upvotes: 12

Divanshu Aggarwal
Divanshu Aggarwal

Reputation: 446

  • When you create a lambda function you will see option to choose language.
  • Choose python
  • Create function
  • As soon as function is created you will see edit inline option and a file of your lambda_function_name/lambda_function.py with code

    import json.
    def lambda_handler(event, context):
    return {
     'statusCode': 200,
     'body': json.dumps('Hello from Lambda!')
    }
    

you can edit this based upon requirement.This is inline.

Upvotes: -1

Related Questions