5

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.

2 Answers 2

12

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
Sign up to request clarification or add additional context in comments.

4 Comments

Just for the sake of reference, Can you point to the documentation of Code: ZipFile > section?
The documentation you already linked states, that the Zipfile property allows for inline code. The rest is basically YAML syntax (and a lot of trial and error).
@shantanuo Here is AWS example with inline code docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/…
I am wondering why you have used > insead of a pipe | ?
-1
  • 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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.