Skip to content
GitHubXDiscord

ApiKey

The ApiKey resource lets you manage AWS ApiGateway ApiKeys to control access to your APIs. This resource enables you to create, update, and delete API keys as well as manage their stage keys and other properties.

Create a basic API key with a description and enabled status:

import AWS from "alchemy/aws/control";
const apiKey = await AWS.ApiGateway.ApiKey("myApiKey", {
name: "MyFirstApiKey",
description: "This is my first API key for accessing the API.",
enabled: true
});

Configure an API key with a customer ID and distinct ID generation:

const advancedApiKey = await AWS.ApiGateway.ApiKey("myAdvancedApiKey", {
name: "MyAdvancedApiKey",
description: "An advanced API key configuration.",
enabled: true,
customerId: "customer-12345",
generateDistinctId: true,
tags: [
{ key: "environment", value: "production" },
{ key: "team", value: "backend" }
]
});

Create an API key and bind it to specific stages of an API:

const stageKeys = [
{
restApiId: "api-123456",
stageName: "prod"
},
{
restApiId: "api-123456",
stageName: "dev"
}
];
const stageBoundApiKey = await AWS.ApiGateway.ApiKey("myStageBoundApiKey", {
name: "MyStageBoundApiKey",
description: "API key bound to specific stages.",
enabled: true,
stageKeys: stageKeys
});

Create an API key with a specific key value:

const customValueApiKey = await AWS.ApiGateway.ApiKey("myCustomValueApiKey", {
name: "MyCustomValueApiKey",
description: "API key with a custom value.",
value: "customKeyValue123",
enabled: true
});