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

Fix stage name handling #579

Merged
merged 21 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
"@aws-sdk/config-resolver": "^3.329.0",
"@aws-sdk/credential-providers": "^3.329.0",
"@aws-sdk/node-config-provider": "^3.329.0",
"@aws-sdk/smithy-client": "^3.329.0"
"@aws-sdk/smithy-client": "^3.329.0",
"@aws-sdk/util-retry": "^3.329.0"
},
"peerDependencies": {
"serverless": "^2.60 || ^3.0.0"
Expand Down
3 changes: 2 additions & 1 deletion src/aws/api-gateway-v1-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class APIGatewayV1Wrapper extends APIGatewayBase {
super();
this.apiGateway = new APIGatewayClient({
credentials,
region: Globals.getRegion()
region: Globals.getRegion(),
retryStrategy: APIGatewayBase.getRetryStrategy()
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/aws/api-gateway-v2-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class APIGatewayV2Wrapper extends APIGatewayBase {
super();
this.apiGateway = new ApiGatewayV2Client({
credentials,
region: Globals.getRegion()
region: Globals.getRegion(),
retryStrategy: APIGatewayBase.getRetryStrategy()
});
}

Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,12 @@ class ServerlessCustomDomain {
domain.domainInfo = await apiGateway.getCustomDomain(domain);

if (!domain.apiMapping) {
if (domain.apiType === Globals.apiTypes.http) {
Logging.logWarning(
"Make sure that the API Mapping with the `$default` stage already exists. " +
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm what are people supposed to do when they see this warning?

"More info here https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-stages.html"
)
}
await apiGateway.createBasePathMapping(domain);
} else {
await apiGateway.updateBasePathMapping(domain);
Expand Down
10 changes: 10 additions & 0 deletions src/models/apigateway-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@ import DomainInfo = require("./domain-info");
import ApiGatewayMap = require("./api-gateway-map");
import DomainConfig = require("./domain-config");
import {Client} from "@aws-sdk/smithy-client";
import {ConfiguredRetryStrategy} from "@aws-sdk/util-retry";

abstract class APIGatewayBase {
public apiGateway: Client<any, any, any, any>;

public static getRetryStrategy() {
rddimon marked this conversation as resolved.
Show resolved Hide resolved
return new ConfiguredRetryStrategy(
5, // max attempts.
// This example sets the backoff at 100ms plus 5s per attempt.
// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_util_retry.html#aws-sdkutil-retry
(attempt: number) => 100 + attempt * 5000 // backoff function.
rddimon marked this conversation as resolved.
Show resolved Hide resolved
)
}

abstract createCustomDomain(domain: DomainConfig): Promise<DomainInfo>;

abstract getCustomDomain(domain: DomainConfig): Promise<DomainInfo>;
Expand Down
6 changes: 5 additions & 1 deletion test/integration-tests/apigateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ import {
GetResourcesCommand,
GetResourcesCommandOutput
} from "@aws-sdk/client-api-gateway";
import APIGatewayBase = require("../../src/models/apigateway-base");

export default class APIGatewayWrap {
private client: APIGatewayClient;

constructor(region: string) {
this.client = new APIGatewayClient({region});
this.client = new APIGatewayClient({
region,
retryStrategy: APIGatewayBase.getRetryStrategy()
});
}

/**
Expand Down
2 changes: 2 additions & 0 deletions test/integration-tests/basic/http-api-multiple/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ custom:
basePath: ''
endpointType: REGIONAL
autoDomain: true
stage: '$default'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required now? This could be considered a breaking change. Is it possible to default to $default for http APIs?

- http:
domainName: ${env:PLUGIN_IDENTIFIER}-http-api-milti2-${env:RANDOM_STRING}.${env:TEST_DOMAIN}
basePath: ''
endpointType: REGIONAL
autoDomain: true
stage: '$default'

package:
patterns:
Expand Down