Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve path mapping deletion #478

Merged
merged 13 commits into from
Jan 26, 2022
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [5.6.0] - 2021-01-26
- Added config option to avoid automatically deleting an APIGW domain when other base path mappings exist. Thank you @straticJeff ([389](https://github.com/amplify-education/serverless-domain-manager/pull/389))

## [5.5.0] - 2021-01-24
- Added proxy support. Thank you @mscharp ([405](https://github.com/amplify-education/serverless-domain-manager/pull/405))
- Fixed issue with disabling createRoute53Record. Thank you @albinlundmark ([476](https://github.com/amplify-education/serverless-domain-manager/pull/476))
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ allowPathMatching | false | When updating an existing api mapping this will matc
| route53Params:<br/>&nbsp; weight | `200` | Sets the weight for weighted routing. Ignored for `simple` and `latency` routing. |
| route53Params:<br/>&nbsp; setIdentifier | | A unique identifier for records in a set of Route 53 records with the same domain name. Only relevant for `latency` and `weighted` routing. Defaults to the regional endpoint if not provided. |
| route53Params:<br/>&nbsp; healthCheckId | | An optional id for a Route 53 health check. If it is failing, Route 53 will stop routing to it. Only relevant for `latency` and `weighted` routing. If it is not provided, no health check will be associated with the record. |
| preserveExternalPathMappings | `false` | When `autoDomain` is set to true, and a deployment is removed, setting this to `true` checks for additional API Gateway base path mappings before automatically deleting the domain, and avoids doing so if they exist. |



## Running
Expand Down
102 changes: 52 additions & 50 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-domain-manager",
"version": "5.5.0",
"version": "5.6.0",
"engines": {
"node": ">=12"
},
Expand Down Expand Up @@ -47,7 +47,7 @@
},
"devDependencies": {
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.10",
"@types/node": "^17.0.12",
"aws-sdk-mock": "^5.6.0",
"chai": "^4.3.4",
"chai-spies": "^1.0.0",
Expand All @@ -57,7 +57,7 @@
"randomstring": "^1.2.2",
"request": "^2.88.2",
"request-promise-native": "^1.0.9",
"serverless": "^2.72.1",
"serverless": "^2.72.2",
"serverless-plugin-split-stacks": "^1.11.3",
"shelljs": "^0.8.5",
"ts-node": "^10.4.0",
Expand Down
13 changes: 2 additions & 11 deletions src/aws/api-gateway-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,25 +148,16 @@ class APIGatewayWrapper {
}
}

/**
* Get basepath mapping
*/
public async getBasePathMapping(domain: DomainConfig): Promise<ApiGatewayV2.GetApiMappingResponse> {
public async getApiMappings(domain: DomainConfig): Promise<ApiGatewayV2.GetApiMappingResponse[]> {
try {
const mappings = await getAWSPagedResults(
return await getAWSPagedResults(
this.apiGatewayV2,
"getApiMappings",
"Items",
"NextToken",
"NextToken",
{DomainName: domain.givenDomainName},
);
for (const mapping of mappings) {
if (mapping.ApiId === domain.apiId
|| (mapping.ApiMappingKey === domain.basePath && domain.allowPathMatching)) {
return mapping;
}
}
} catch (err) {
Globals.logError(err, domain.givenDomainName);
throw new Error(`Unable to get API Mappings for ${domain.givenDomainName}`);
Expand Down
2 changes: 2 additions & 0 deletions src/domain-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class DomainConfig {
public autoDomain: boolean | undefined;
public autoDomainWaitFor: string | undefined;
public route53Params: Route53Params;
public preserveExternalPathMappings: boolean | undefined;

public domainInfo: DomainInfo | undefined;
public apiId: string | undefined;
Expand All @@ -50,6 +51,7 @@ class DomainConfig {
this.allowPathMatching = config.allowPathMatching;
this.autoDomain = config.autoDomain;
this.autoDomainWaitFor = config.autoDomainWaitFor;
this.preserveExternalPathMappings = this.evaluateBoolean(config.preserveExternalPathMappings, false);

let basePath = config.basePath;
if (basePath == null || basePath.trim() === "") {
Expand Down
Loading