Skip to content
GitHubXDiscordRSS

ApiMapping

Learn how to create, update, and manage AWS ApiGatewayV2 ApiMappings using Alchemy Cloud Control.

The ApiMapping resource allows you to create and manage API mappings for your AWS ApiGatewayV2 instances. API mappings define how your API is exposed on a custom domain name. For more information, visit the AWS ApiGatewayV2 ApiMappings documentation.

Create a basic API mapping with required properties.

import AWS from "alchemy/aws/control";
const basicApiMapping = await AWS.ApiGatewayV2.ApiMapping("basicApiMapping", {
DomainName: "api.example.com",
Stage: "production",
ApiId: "1234567890",
ApiMappingKey: "/v1" // Optional
});

Configure an API mapping with additional options, such as a specific mapping key.

const advancedApiMapping = await AWS.ApiGatewayV2.ApiMapping("advancedApiMapping", {
DomainName: "api.example.com",
Stage: "dev",
ApiId: "0987654321",
ApiMappingKey: "v2", // Optional, defines the path for the mapping
adopt: true // Optional, if true, adopts existing resource if it already exists
});

Create multiple API mappings for different stages of your application.

const productionApiMapping = await AWS.ApiGatewayV2.ApiMapping("productionApiMapping", {
DomainName: "api.example.com",
Stage: "production",
ApiId: "1234567890",
ApiMappingKey: "/prod" // Maps the production stage
});
const stagingApiMapping = await AWS.ApiGatewayV2.ApiMapping("stagingApiMapping", {
DomainName: "api.example.com",
Stage: "staging",
ApiId: "1234567890",
ApiMappingKey: "/staging" // Maps the staging stage
});

Create an API mapping for a custom domain with a specific API ID and stage.

const customDomainApiMapping = await AWS.ApiGatewayV2.ApiMapping("customDomainApiMapping", {
DomainName: "custom.api.example.com",
Stage: "beta",
ApiId: "1122334455",
ApiMappingKey: "beta" // Custom path for the beta stage
});