nymvno
nymvno

Reputation: 400

Get information about already delpoyed AWSLambda function to create an similar deployment template

Is there a possibility to get all the information that I need to deploy a lambda function with all its needed dependencies (Permissions, Policies, Invocation Event files) to auto-deploy it later from a template via AWS SAM CLI (or anything similar)?

Is there an option to retrace how the lambda function was set up afterwards without using the UI elements so that this can be done in an automated fashion?

My plan is to gather the serverless application model from an already deployed serverless application on AWS Lambda. I do not struggle in deploying a function on any platform but want to investigate the possibility to take a serverless application from one provider (here: AWS) and migrate it to another platform (say: Azure) in an automated fashion. That exactly is the plan. As far as I know, all existing frameworks focus on provider-agnostic deployment of serverless functions but I want to take one function with all its architectural relations (e.g. events based on S3 triggers) and migrate it to another providers platform with comparable Services.

TLDR: I want to extract an already existing deployed Lambda function and get information similar to the information that I pass in the SAM CLI template to initial deploy a serverless function on AWS.

One function could be the common example of thumbnail creation via S3 buckets.

Upvotes: 1

Views: 123

Answers (1)

Hugo Lesta
Hugo Lesta

Reputation: 779

Have you tried Terraform?

Terraform is able to return outputs and set lambdas and infrastructure as a code therefore, you should able to deploy easily another lambda using only one terraform apply command in yor cli.

Starting using terraform, first learn a little bit about terraform installation

Create a main.tf, variables.tf, output.tf and terraform.tfvars

Use git to versioning your terraform code, after learn how to use terraform you should learn how to build a terraform modules, because using this is the strongest way to use it.

You should add terraform code into main.tf, remember that you always need reference a new variable when you need to use that into variables.tf file. the variables are set into terraform.tfvars, output.tf will have attribute reference you need for returning values using terraform output command or you can use the outputs as variables in another terraform configuration.

For apply Policies or Roles, you can make it in a .tpl file and build a terraform template function.

Getting started with lambda:

Terraform Lambda documentation: https://www.terraform.io/docs/providers/aws/r/lambda_function.html

You should zip your code and add a zip file name in source_code_hash reference and then upload using this terraform configuration. You can follow the same example of terraform lambda documentation.

Once lambda is deployed as a module, you can use the following command terraform output -module=

For example, an amazon-web-service networking module can return the following information but the same way you can use lambda output for retrieving some data information like below:

application_subnet_cidrs = [
    172.26.36.0/24,
    172.26.38.0/24
]
application_subnets = [
    subnet-0cc58542e12abf485,
    subnet-0bab1bffc0af1b14e
]
persistence_subnet_cidrs = [
    172.26.39.0/24,
    172.26.40.0/24
]
persistence_subnets = [
    subnet-0db668829e4849612,
    subnet-031c4ff888b1e3d3b
]
public_subnets = [
    subnet-096db791faf60cc20,
    subnet-04a305177a6bac31c
]
vpc_id = vpc-0f2fdb66b7ae73e5c

I hope it may help you

Upvotes: 1

Related Questions