0

Is there any way to get the cloudformation for lambdas? I know you can create AWS CloudFormation Templates from existing AWS Resources using CloudFormer. And also, cloudformer is in beta mode (AWS CloudFormer 0.41 (Beta)) at the time I am asking this question. While following the documentation, I could not find a way to create cloudformation for my lambda

I have selected everything while creating the cloudformation but the template contains no lambdas.

Is it not supported or I am missing something? If it is not supported, what is the reason behind this?

Daniel B.
  • 1,650
  • 1
  • 19
  • 40
MJK
  • 3,434
  • 3
  • 32
  • 55
  • 1
    Seems like there is no way, however the below link helps me. Hope it is useful to you as well. https://stackoverflow.com/questions/50906085/export-existing-aws-lambda-and-api-gateway-to-cloudformation-template – sayboras Aug 06 '18 at 11:38
  • There is no much of a secret for the lambda clouformation. I can share my yaml template here in the answers. – Cleriston May 28 '19 at 03:29
  • @Cleriston thanks, I was looking for a way to export cloudFormation template. The link in other comments demonstrate a way – MJK May 29 '19 at 07:35
  • The example has a config for AWS SAM, which is diff of CloudFormation. It has a different code management procedure. However, if it is what you are looking for, I dont have much to say. Cheers. – Cleriston May 30 '19 at 00:43

1 Answers1

1

If you save the Lambda code to disk, you could use Rubycfn to create your Lambda function in CloudFormation.

gem install rubycfn

Save the file below to example.rb and run rubycfn example.rb to generate the CloudFormation.

def file_to_inline(filename)
  File.open(filename).read.split("\n")
end

resource :my_lambda_function,
         type: "AWS::Lambda::Function" do |r|
  r.property(:code) do
    {
      "ZipFile": file_to_inline("/path/to/lambda.py").fnjoin("\n")
    }
  end
  r.property(:role) { :your_lambda_role.ref(:arn) }
  r.property(:handler) { "index.lambda_handler" }
  r.property(:runtime) { "some_runtime" }
end
Dennis
  • 779
  • 4
  • 14