Skip to content
GitHubXDiscord

UsagePlanKey

The UsagePlanKey resource allows you to create, update, and manage AWS ApiGateway UsagePlanKeys which are used to associate API keys with usage plans in Amazon API Gateway.

Create a basic UsagePlanKey with required properties.

import AWS from "alchemy/aws/control";
const usagePlanKey = await AWS.ApiGateway.UsagePlanKey("basicUsagePlanKey", {
KeyType: "API_KEY",
UsagePlanId: "12345678-abcd-efgh-ijkl-123456789012",
KeyId: "sample-api-key-id",
adopt: true // Indicating to adopt an existing resource if it already exists
});

Create a UsagePlanKey with additional configurations if necessary.

const advancedUsagePlanKey = await AWS.ApiGateway.UsagePlanKey("advancedUsagePlanKey", {
KeyType: "API_KEY",
UsagePlanId: "87654321-lkjh-gfed-cba-210987654321",
KeyId: "advanced-api-key-id",
adopt: true // Optional: adopt existing resource
});

Demonstrate how to create multiple UsagePlanKeys for different API keys.

const firstUsagePlanKey = await AWS.ApiGateway.UsagePlanKey("firstUsagePlanKey", {
KeyType: "API_KEY",
UsagePlanId: "abc12345-def6-7890-gh12-ijklmnopqr",
KeyId: "first-api-key-id"
});
const secondUsagePlanKey = await AWS.ApiGateway.UsagePlanKey("secondUsagePlanKey", {
KeyType: "API_KEY",
UsagePlanId: "xyz09876-uvw3-2109-zyxw-tsrqponmlk",
KeyId: "second-api-key-id",
adopt: true // Indicates adopting an existing resource
});

Show how to handle potential errors during the creation of a UsagePlanKey.

try {
const errorHandlingUsagePlanKey = await AWS.ApiGateway.UsagePlanKey("errorHandlingUsagePlanKey", {
KeyType: "API_KEY",
UsagePlanId: "error-usage-plan-id",
KeyId: "error-api-key-id"
});
} catch (error) {
console.error("Error creating UsagePlanKey:", error);
}