A ready-to-use AWS Lambda Layer for the Google Generative AI SDK (@google/genai) for Node.js. This layer allows you to use Google's Gemini API in your AWS Lambda functions without packaging the dependencies yourself.
The easiest way to get started is to use one of our pre-built layers:
| Region | ARN |
|---|---|
| us-east-1 | arn:aws:lambda:us-east-1:449296410387:layer:google-genai:1 |
| us-east-2 | arn:aws:lambda:us-east-2:449296410387:layer:google-genai:1 |
| us-west-1 | arn:aws:lambda:us-west-1:449296410387:layer:google-genai:1 |
| us-west-2 | arn:aws:lambda:us-west-2:449296410387:layer:google-genai:1 |
| eu-west-1 | arn:aws:lambda:eu-west-1:449296410387:layer:google-genai:1 |
| eu-west-2 | arn:aws:lambda:eu-west-2:449296410387:layer:google-genai:1 |
- Open your Lambda function in the AWS Console
- Scroll down to the Layers section
- Click Add a layer
- Select Specify an ARN
- Paste the ARN for your region from the table above
- Click Add
aws lambda update-function-configuration \
--function-name YOUR_FUNCTION_NAME \
--layers arn:aws:lambda:us-east-1:449296410387:layer:google-genai:1Once the layer is attached to your Lambda function, you can use the Google Generative AI SDK:
import {GoogleGenAI} from '@google/genai';
// The client gets the API key from the environment variable `GEMINI_API_KEY`.
const ai = new GoogleGenAI({});
export const handler = async (event) => {
const response = await ai.models.generateContent({
model: "gemini-2.5-flash",
contents: "Explain how AI works in a few words",
});
console.log(response.text);
return response;
};If you need a different region or want to customize the layer:
- Node.js 20.x or 22.x
- npm
- AWS CLI configured with appropriate credentials
- Clone or download this repository
git clone https://github.com/florisalexandrou/google-genai-lambda-layer.git
cd google-genai-lambda-layer- Install dependencies
cd nodejs
npm install
cd ..- Create the layer package
zip -r google-genai-layer.zip nodejs- Publish to AWS Lambda
aws lambda publish-layer-version \
--layer-name google-genai \
--description "Google Generative AI SDK" \
--zip-file fileb://google-genai-layer.zip \
--compatible-runtimes nodejs20.x nodejs22.x \
--compatible-architectures x86_64@google/genaiv1.27.0
- Node.js 20.x
- Node.js 22.x
- x86_64
This layer package is provided as-is. The Google Generative AI SDK is subject to its own license terms.
This is an unofficial AWS Lambda Layer. It is not affiliated with, endorsed by, or sponsored by Google or AWS.
Made with ❤️ for the serverless community