Skip to content

Commit

Permalink
Merge pull request #567 from amplify-education/hotfix/handle-sls-regi…
Browse files Browse the repository at this point in the history
…on-option

Manage the Serverless region parameter
  • Loading branch information
rddimon committed Mar 23, 2023
2 parents 6998493 + 4295636 commit 1be8faf
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,11 @@ 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).

## [7.0.1] - 2022-03-23

### Fixed
- Manage the Serverless `region` parameter.

## [7.0.0] - 2022-03-22

### Changed
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "serverless-domain-manager",
"version": "7.0.0",
"version": "7.0.1",
"engines": {
"node": ">=14"
},
Expand Down Expand Up @@ -78,6 +78,6 @@
"@aws-sdk/smithy-client": "^3.295.0"
},
"peerDependencies": {
"serverless": "^2.60 || 3"
"serverless": "^2.60 || ^3.0.0"
}
}
4 changes: 2 additions & 2 deletions src/aws/acm-wrapper.ts
Expand Up @@ -13,7 +13,7 @@ class ACMWrapper {

constructor(endpointType: string) {
const isEdge = endpointType === Globals.endpointTypes.edge;
this.acm = new ACMClient({region: isEdge ? Globals.defaultRegion : Globals.currentRegion});
this.acm = new ACMClient({region: isEdge ? Globals.defaultRegion : Globals.getRegion()});
}

public async getCertArn(domain: DomainConfig): Promise<string> {
Expand All @@ -23,7 +23,7 @@ class ACMWrapper {
try {
const response: ListCertificatesCommandOutput = await this.acm.send(
new ListCertificatesCommand({CertificateStatuses: certStatuses})
)
);
// enhancement idea: weight the choice of cert so longer expires
// and RenewalEligibility = ELIGIBLE is more preferable
if (certificateName) {
Expand Down
2 changes: 1 addition & 1 deletion src/aws/api-gateway-v1-wrapper.ts
Expand Up @@ -24,7 +24,7 @@ import Logging from "../logging";
class APIGatewayV1Wrapper extends APIGatewayBase {
constructor() {
super();
this.apiGateway = new APIGatewayClient({region: Globals.currentRegion});
this.apiGateway = new APIGatewayClient({region: Globals.getRegion()});
}

public async createCustomDomain(domain: DomainConfig): Promise<DomainInfo> {
Expand Down
2 changes: 1 addition & 1 deletion src/aws/api-gateway-v2-wrapper.ts
Expand Up @@ -25,7 +25,7 @@ class APIGatewayV2Wrapper extends APIGatewayBase {

constructor() {
super();
this.apiGateway = new ApiGatewayV2Client({region: Globals.currentRegion});
this.apiGateway = new ApiGatewayV2Client({region: Globals.getRegion()});
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/aws/cloud-formation-wrapper.ts
Expand Up @@ -20,7 +20,7 @@ class CloudFormationWrapper {

constructor() {
const defaultStackName = Globals.serverless.service.service + "-" + Globals.getBaseStage();
this.cloudFormation = new CloudFormationClient({region: Globals.currentRegion});
this.cloudFormation = new CloudFormationClient({region: Globals.getRegion()});
this.stackName = Globals.serverless.service.provider.stackName || defaultStackName;
}

Expand Down Expand Up @@ -119,7 +119,7 @@ class CloudFormationWrapper {
const response: ListExportsCommandOutput = await this.cloudFormation.send(
new ListExportsCommand({})
);
const exports = response.Exports || []
const exports = response.Exports || [];
// filter Exports by names which we need
const filteredExports = exports.filter((item) => names.indexOf(item.Name) !== -1);
// converting a list of unique values to dict
Expand Down
4 changes: 2 additions & 2 deletions src/aws/route53-wrapper.ts
Expand Up @@ -15,10 +15,10 @@ class Route53Wrapper {
if (credentials) {
this.route53 = new Route53Client({
credentials,
region: region || Globals.currentRegion
region: region || Globals.getRegion()
});
} else {
this.route53 = new Route53Client({region: Globals.currentRegion});
this.route53 = new Route53Client({region: Globals.getRegion()});
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/aws/s3-wrapper.ts
Expand Up @@ -7,7 +7,7 @@ class S3Wrapper {
public s3: S3Client;

constructor() {
this.s3 = new S3Client({region: Globals.currentRegion});
this.s3 = new S3Client({region: Globals.getRegion()});
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/globals.ts
Expand Up @@ -64,6 +64,10 @@ export default class Globals {
return Globals.options.stage || Globals.serverless.service.provider.stage;
}

public static getRegion() {
return Globals.options.region || Globals.currentRegion || Globals.defaultRegion;
}

public static async getProfileCreds(profile: string) {
return await fromIni({profile})();
}
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Expand Up @@ -169,7 +169,9 @@ class ServerlessCustomDomain {
* Init AWS current region
*/
public async initAWSRegion(): Promise<void> {
Globals.currentRegion = await loadConfig(NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS)();
if (!Globals.options.region) {
Globals.currentRegion = await loadConfig(NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS)();
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Expand Up @@ -63,8 +63,9 @@ export interface ServerlessInstance {
addServiceOutputSection?(name: string, data: string[]);
}

export interface ServerlessOptions { // tslint:disable-line
export interface ServerlessOptions {
stage: string;
region?: string;
}

interface ServerlessProgress {
Expand Down
1 change: 1 addition & 0 deletions test/integration-tests/debug/debug.test.ts
Expand Up @@ -14,6 +14,7 @@ describe("Integration Tests", function () {

try {
await utilities.createTempDir(TEMP_DIR, configFolder);
await utilities.slsCreateDomain(TEMP_DIR, true);
await utilities.slsDeploy(TEMP_DIR, true);
} finally {
await utilities.destroyResources(testName);
Expand Down
5 changes: 3 additions & 2 deletions test/integration-tests/test-utilities.ts
Expand Up @@ -39,10 +39,11 @@ async function createTempDir(tempDir, folderName) {
/**
* Runs `sls create_domain` for the given folder
* @param tempDir
* @param debug - enable loging
* @returns {Promise<void>}
*/
function slsCreateDomain(tempDir) {
return exec(`cd ${tempDir} && npx serverless create_domain`);
function slsCreateDomain(tempDir, debug: boolean = false) {
return exec(`cd ${tempDir} && npx serverless create_domain --stage test --region us-east-1` + (debug ? " --verbose" : ""));
}

/**
Expand Down

0 comments on commit 1be8faf

Please sign in to comment.