Skip to content
GitHubXDiscordRSS

BasePathMappingV2

Learn how to create, update, and manage AWS ApiGateway BasePathMappingV2s using Alchemy Cloud Control.

The BasePathMappingV2 resource allows you to manage AWS ApiGateway BasePathMappingV2s that define the mapping between a custom domain name and a specific API Gateway REST API.

Create a basic BasePathMappingV2 linking a domain name to an API Gateway REST API:

import AWS from "alchemy/aws/control";
const basePathMapping = await AWS.ApiGateway.BasePathMappingV2("basicMapping", {
DomainNameArn: "arn:aws:apigateway:us-west-2::/domainnames/example.com",
RestApiId: "abcdefghij",
Stage: "prod", // Optional stage
BasePath: "v1" // Optional base path
});

Configure a BasePathMappingV2 for an API with an optional base path and adopt existing resources:

const advancedBasePathMapping = await AWS.ApiGateway.BasePathMappingV2("advancedMapping", {
DomainNameArn: "arn:aws:apigateway:us-west-2::/domainnames/api.example.com",
RestApiId: "klmnopqrst",
Stage: "dev", // Optional stage
BasePath: "v2", // Optional base path
adopt: true // Adopt existing resource if it exists
});

Create a BasePathMappingV2 that uses a custom base path to route requests effectively:

const customBasePathMapping = await AWS.ApiGateway.BasePathMappingV2("customMapping", {
DomainNameArn: "arn:aws:apigateway:us-west-2::/domainnames/api.example.com",
RestApiId: "uvwxyz1234",
BasePath: "api/v1", // Custom base path for API versioning
Stage: "prod" // Specify the production stage
});

Set up a BasePathMappingV2 that uses the default base path and a specified stage only:

const defaultBasePathMapping = await AWS.ApiGateway.BasePathMappingV2("defaultMapping", {
DomainNameArn: "arn:aws:apigateway:us-west-2::/domainnames/example.com",
RestApiId: "mnopqrstuv",
Stage: "test" // Stage without a custom base path
});