Save money by deploying your lambda on ARM with CDK

I am a french Developer, working for a french startup :) i like video games, computers and drinking Ricoré
Search for a command to run...

I am a french Developer, working for a french startup :) i like video games, computers and drinking Ricoré
No comments yet. Be the first to comment.
AWS Bedrock AgentCore lets you deploy agents as managed containerized runtimes. This guide shows how to automate this deployment using Pulumi and Docker. What You'll Deploy Docker container with your agent code Amazon ECR to store the image Bedroc...

Introduction This guide shows how to deploy AWS Bedrock Agents using Pulumi and TypeScript. Prerequisites AWS Account with Bedrock access Node.js and npm installed Pulumi CLI installed Project Setup Generate Project with Pulumi pulumi new aws-t...

Starting My Homelab Journey with a Raspberry Pi 4B

I recently discovered Docker compose profiles and wanted to share it as it can be useful to someone else. Docker Compose profiles let you control which services run without modifying your docker-compose.yml. They’re useful for separating optional s...

These days, i’m using AWS Bedrock to create Agents.And i faced this error when testing my agents many times so i decided to write down the workaround that i found. An error occurred (dependencyFailedException) when calling the InvokeAgent operation: ...

In 2018, AWS launched their first EC2 instances powered by ARM-based AWS Graviton Processors. These are 64-bit Arm-based processors that are custom built by AWS and offer a better price to performance ratio. The second generation (AWS Graviton2) of processors deliver 7x more performance, 4x more compute cores, 5x faster memory, and 2x larger caches.
AWS launched Graviton2 support for AWS Lambda Functions, which means that Lambda Functions can now execute on Graviton2 processors and take advantage of the improved price performance of that architecture.
In this article, i'll show you how to configure the processor using AWS CDK.
Let's create the main folder of the project
mkdir armLambda
cd armLambda
npm init -y
Then install CDK and aws-lambda package
npm install -g aws-cdk
npm i @aws-cdk/aws-lambda
mkdir cdk-folder
cd cdk-folder
cdk init app --language typescript
Open the file lib/cdk-folder-stack.ts
import * as cdk from '@aws-cdk/core';
import * as lambda from '@aws-cdk/aws-lambda';
import { Architecture } from '@aws-cdk/aws-lambda';
import * as path from 'path';
export class CdkFolderStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// The code that defines the lambda
const myLambdaFunction = new lambda.Function(this, 'my-lambda', {
runtime: lambda.Runtime.NODEJS_14_X,
memorySize: 256,
timeout: cdk.Duration.seconds(60),
handler: 'index.main',
// 🤖 --- this line below makes all the difference --- 🤖
architecture: Architecture.ARM_64,
code: lambda.Code.fromAsset(path.join(__dirname, '/../app')),
});
}
We are going to create a folder for the lambda at the root (next to lib) :
Let's create a simple lambda that fetches the time on a free API
mkdir app
cd app
mkdir my-lambda
cd my-lambda
npm init -y
touch index.js
Here is the code for a super simple lambda :)
export async function main(event) {
console.log("Hello ARM Lambda");
}
Let's bootstrap first
cdk bootstrap
⏳ Bootstrapping environment aws://XXXXXXXXXXXXX/us-east-1...
✅ Environment aws://XXXXXXXXXXXXXX/us-east-1 bootstrapped (no changes).
Second command, to create the Cloudformation template for our app :
cdk synth
And now, let's deploy !
cdk deploy
On the console, go to Lambda > your lambda

Congrats !
Now you can save some money ! 💰
Don't forget to clean after this tutorial, i don't want you to have a huge bill on AWS!
cdk destroy
As you can see, it's pretty simple with CDK to deploy your lambdas on ARM.
Let me know if you have any question in the comments ;)