serverless-tag-resources
Version:
Datamart: Tag all AWS resources with dual legacy + datamart:* tag support
43 lines (38 loc) • 1.62 kB
JavaScript
;
const {
ApiGatewayV2Client,
TagResourceCommand,
} = require("@aws-sdk/client-apigatewayv2");
const { getClient } = require("../aws-clients");
async function tagApiGatewayV2(config, resource, tagsMap, partition, region, allStackResources) {
const client = getClient(ApiGatewayV2Client, config);
switch (resource.ResourceType) {
case "AWS::ApiGatewayV2::Api": {
const arn = `arn:${partition}:apigateway:${region}::/apis/${resource.PhysicalResourceId}`;
await client.send(new TagResourceCommand({ ResourceArn: arn, Tags: tagsMap }));
break;
}
case "AWS::ApiGatewayV2::Stage": {
// Find the parent API in the same stack
const apiResource = allStackResources.find(
(r) => r.ResourceType === "AWS::ApiGatewayV2::Api"
);
if (apiResource) {
const arn = `arn:${partition}:apigateway:${region}::/apis/${apiResource.PhysicalResourceId}/stages/${resource.PhysicalResourceId}`;
await client.send(new TagResourceCommand({ ResourceArn: arn, Tags: tagsMap }));
}
break;
}
case "AWS::ApiGatewayV2::DomainName": {
const arn = `arn:${partition}:apigateway:${region}::/domainnames/${resource.PhysicalResourceId}`;
await client.send(new TagResourceCommand({ ResourceArn: arn, Tags: tagsMap }));
break;
}
case "AWS::ApiGatewayV2::VpcLink": {
const arn = `arn:${partition}:apigateway:${region}::/vpclinks/${resource.PhysicalResourceId}`;
await client.send(new TagResourceCommand({ ResourceArn: arn, Tags: tagsMap }));
break;
}
}
}
module.exports = { tagApiGatewayV2 };