In this article, We will be looking at how to migrate an AWS lambda function deployed as a Serverless application into a Pulumi project without modifying the underlying lambda code.

This article assumes that you have a basic understanding of serverless framework and .

You can find the complete code for this article on GitHub.

Our existing Serverless Framework implementation

Let us first imagine that we have a serverless application with a single lambda function ( createTodo) deployed in AWS. To make it interesting, we will use the code from typescript todo rest api example serverless examples repository.

The project structure could look something like this:

todos-api 
├─ .eslintrc.json
├─ functions 
│  └─ create.ts 
├─ package.json 
├─ package-lock.json 
├─ serverless.yml 
└─ tsconfig.json

serverless.yml could look as follows:

And we deploy with the following command

$ cd todos-api
$ serverless deploy

This would create the following AWS resources:

  • CloudFormation template used to provision the stack
  • S3 bucket where zip files of the function are stored
  • Lambda serverless application
  • Lambda function, belonging to the application
  • CloudWatch log group with log streams for each instance of the function
  • Dynamodb Table resource
  • Role attached to the function with the following policies:
  • An “assume role” policy with a permission for AWS Lambda service to assume this role
  • A policy allowing the CloudWatch log group to create log streams and put log events to these streams
  • A policy allowing dynamodb PUT operation
  • REST API Gateway with:
  • the _/new_ POST endpoint integrated with the function
  • a permission to invoke the function

After we implement the Lambda function with Pulumi, we will have pretty much the same set of resources, except for the:

  • CloudFormation template
  • S3 bucket
  • Lambda serverless application

So you can remove them after you’ve moved your function.

#serverless #pulumi #nodejs #aws-lambda

Migrating AWS Lambda to Pulumi Project From Serverless
5.50 GEEK