AWS recently launched support for Graviton2 in AWS Lambda Functions but if your organization is using IaC with Serverless framework, you will notice that it is not natively offering the option to use ARM64 yet. At Cloudwiry we addressed this with a quick but elegant and scalable solution: we created a tiny plugin that can be easily plugged into any software building pipeline with non-disruptive effects.
The plugin is publicly available at serverless-aws-lambda-arch repository and can be used like this for a new or even existing codebase.
- Go to your project serverless.yml and reference the plugin
- Add/mark the desired functions that you want to use with graviton2
- Install the plugin
- Have fun testing/deploying
Details are explained in the next sections.
Referencing the plugin
Add the plugin to the serverless.yaml file by adding the last entry in the plugins section.
This section may contain other plugins depending on the serverless features your code is already using, just add a mention to
serverless-aws-lambda-arch at the end.
Marking the desired functions that will use Graviton2
In serverless.yml, go to the functions section and add the architectures to each function entry that you want to use with Graviton2.
Again your codebase may have multiple entries under your functions, add
architectures: arm64 to the entries that you want to migrate. In our case, we are applying this to all our functions: myHappyFunction and myHappyFunction2.
Installing the plugin
Go to your command line console and use this command to install the Cloudwiry provided plugin for serverless framework.
npm install --save --dev @firstname.lastname@example.org
Deploying and Testing
Just use your regular procedure for deployment and testing. In our case, a standalone call to
sls deploy is enough.
Just one caveat
If you depend on native binaries, your development environment needs to be ARM64-compatible in order to be able to produce the right artifacts. This is easy to solve: launching/migrating your pipeline execution to a Graviton2-based EC2 instance.
In this article, we have discovered how to take advantage of ARM64 architecture for one of our favorite services: AWS Lambda Functions. We tested it and described how to take advantage of this for new or existing codebases that rely on Serverless framework. We already have talked about Graviton2 powered AWS Lambda functions previously at AWS Lambda functions with Graviton2 blog article.