Sub topic 9
Graviton in Lambda, Fargate and managed databases
This chapter assumes you know the Arm64 compatibility checks and the multi-architecture image build from the earlier chapters. You should also be able to read an AWS CLI command and a JSON task definition.
Managed services are often the easiest place to start with Graviton. AWS runs the operating system and the host, so your work is limited to choosing the architecture and checking your own code and dependencies.
The working model
Each service exposes the processor choice differently.
| Service | Where you choose Graviton | What you must verify |
|---|---|---|
| Lambda | The function's `architectures` setting (`arm64`) | Native libraries in the zip, layers, or container image are built for arm64 |
| Fargate | `runtimePlatform.cpuArchitecture` in the task definition (`ARM64`) | The container image has an arm64 variant |
| RDS, Aurora, ElastiCache, OpenSearch | The instance class, such as one with a `g` suffix (`db.r6g`, `db.r7g`) | The engine version supports that class |
The first two run your code on Arm64, so compatibility matters. In managed databases AWS ships the engine binaries, so your application usually does not change. Only the instance class does.
Lambda
Lambda functions default to x86_64. To create a function on Graviton, set the architecture at creation:
aws lambda create-function \
--function-name my-fn \
--runtime python3.12 \
--architectures arm64 \
--handler app.handler \
--role arn:aws:iam::111122223333:role/my-fn-role \
--zip-file fileb://function.zipTo switch an existing function, upload code built for arm64 and change the architecture in the same call:
aws lambda update-function-code \
--function-name my-fn \
--architectures arm64 \
--zip-file fileb://function-arm64.zipPure Python, Node.js or Java code runs unchanged. The common error is a zip built on an x86 laptop that contains compiled wheels or native add-ons. The function deploys, then fails at import time. Build the package for arm64 (for example with pip install --platform manylinux2014_aarch64 --only-binary=:all:) or use a container image built for linux/arm64. Layers must also be compatible with arm64.
Arm64 Lambda is billed at a lower price per GB-second than x86, so measure duration after the switch. Cost per request depends on both price and duration.
Fargate
In a Fargate task definition, set the CPU architecture in runtimePlatform:
{
"family": "my-app",
"requiresCompatibilities": ["FARGATE"],
"networkMode": "awsvpc",
"cpu": "512",
"memory": "1024",
"runtimePlatform": {
"cpuArchitecture": "ARM64",
"operatingSystemFamily": "LINUX"
},
"containerDefinitions": [
{
"name": "app",
"image": "111122223333.dkr.ecr.us-east-1.amazonaws.com/my-app:1.0.0",
"essential": true
}
]
}The tag from the multi-architecture build chapter works here, because the registry serves the arm64 variant to an ARM64 task. If the image has only an amd64 variant, the task fails to start with an exec format error. The task definition itself is valid, so the failure appears only at run time. Check the stopped task's reason in ECS.
Managed databases
For RDS and Aurora, moving to Graviton means changing the instance class:
aws rds modify-db-instance \
--db-instance-identifier my-db \
--db-instance-class db.r6g.large \
--apply-immediatelyChanging the class causes an outage. On a Multi-AZ deployment the failover is short. On a single-AZ instance, the instance is unavailable while it is modified. For Aurora, add a Graviton reader to the cluster, fail over to it, and then remove the old x86 instances. This lets you test the new class before it takes writes.
Two checks prevent most failures:
- Confirm that your engine and version offer the Graviton class in your Region. Older minor versions may not.
- Check your extensions. Most are shipped by AWS, but verify any that matter to you in a test environment.
ElastiCache and OpenSearch Service follow the same pattern. You select a g instance type, and the service handles the rest. Because the engine is the same, benchmark with your real query and cache workload instead of assuming the gain.
Common errors
- Building a Lambda zip or image on an x86 machine and deploying it as arm64.
- Pushing a single-architecture image and pointing an ARM64 Fargate task at it.
- Switching a single-AZ database at peak hours.
- Skipping the benchmark and assuming the lower list price means lower cost.
Exercise
A Lambda function was moved to arm64 and deploys successfully, but every invocation fails with an import error for a compiled library. What is the most likely cause, and how do you fix it?
Show answer
The deployment package contains a native library compiled for x86-64. Rebuild the package for arm64, for example with pip's aarch64 platform wheels or on an arm64 build host, or deploy an image built for linux/arm64, then update the function code.
Exercise
Why is adding an Aurora Graviton reader and failing over to it safer than modifying the writer's instance class in place?
Show answer
You can test the Graviton instance as a reader first. The failover is short, and the old x86 instances stay in the cluster until the new one proves stable, which gives you a rollback path.