diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fce023e..e529a5f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/package-lock.json b/package-lock.json index 2dd34180..228de422 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,7 +42,7 @@ "node": ">=14" }, "peerDependencies": { - "serverless": "^2.60 || 3" + "serverless": "^2.60 || ^3.0.0" } }, "node_modules/@ampproject/remapping": { diff --git a/package.json b/package.json index 28e8852a..99413e07 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-domain-manager", - "version": "7.0.0", + "version": "7.0.1", "engines": { "node": ">=14" }, @@ -78,6 +78,6 @@ "@aws-sdk/smithy-client": "^3.295.0" }, "peerDependencies": { - "serverless": "^2.60 || 3" + "serverless": "^2.60 || ^3.0.0" } } diff --git a/src/aws/acm-wrapper.ts b/src/aws/acm-wrapper.ts index aaa783f3..0b8380d8 100644 --- a/src/aws/acm-wrapper.ts +++ b/src/aws/acm-wrapper.ts @@ -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 { @@ -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) { diff --git a/src/aws/api-gateway-v1-wrapper.ts b/src/aws/api-gateway-v1-wrapper.ts index 073d5507..04d38cc3 100644 --- a/src/aws/api-gateway-v1-wrapper.ts +++ b/src/aws/api-gateway-v1-wrapper.ts @@ -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 { diff --git a/src/aws/api-gateway-v2-wrapper.ts b/src/aws/api-gateway-v2-wrapper.ts index b58b494c..1da31f15 100644 --- a/src/aws/api-gateway-v2-wrapper.ts +++ b/src/aws/api-gateway-v2-wrapper.ts @@ -25,7 +25,7 @@ class APIGatewayV2Wrapper extends APIGatewayBase { constructor() { super(); - this.apiGateway = new ApiGatewayV2Client({region: Globals.currentRegion}); + this.apiGateway = new ApiGatewayV2Client({region: Globals.getRegion()}); } /** diff --git a/src/aws/cloud-formation-wrapper.ts b/src/aws/cloud-formation-wrapper.ts index 4d15a713..bfd59e8c 100644 --- a/src/aws/cloud-formation-wrapper.ts +++ b/src/aws/cloud-formation-wrapper.ts @@ -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; } @@ -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 diff --git a/src/aws/route53-wrapper.ts b/src/aws/route53-wrapper.ts index de50881b..3b44584e 100644 --- a/src/aws/route53-wrapper.ts +++ b/src/aws/route53-wrapper.ts @@ -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()}); } } diff --git a/src/aws/s3-wrapper.ts b/src/aws/s3-wrapper.ts index dd66adc4..6c56b271 100644 --- a/src/aws/s3-wrapper.ts +++ b/src/aws/s3-wrapper.ts @@ -7,7 +7,7 @@ class S3Wrapper { public s3: S3Client; constructor() { - this.s3 = new S3Client({region: Globals.currentRegion}); + this.s3 = new S3Client({region: Globals.getRegion()}); } /** diff --git a/src/globals.ts b/src/globals.ts index 44f23d47..ea7080b9 100644 --- a/src/globals.ts +++ b/src/globals.ts @@ -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})(); } diff --git a/src/index.ts b/src/index.ts index 4833dcae..d92ccb64 100644 --- a/src/index.ts +++ b/src/index.ts @@ -169,7 +169,9 @@ class ServerlessCustomDomain { * Init AWS current region */ public async initAWSRegion(): Promise { - 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)(); + } } /** diff --git a/src/types.ts b/src/types.ts index 4e219aa9..b41338a6 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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 { diff --git a/test/integration-tests/debug/debug.test.ts b/test/integration-tests/debug/debug.test.ts index 2b553bc5..29ebda15 100644 --- a/test/integration-tests/debug/debug.test.ts +++ b/test/integration-tests/debug/debug.test.ts @@ -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); diff --git a/test/integration-tests/test-utilities.ts b/test/integration-tests/test-utilities.ts index 3e69807b..b2634755 100644 --- a/test/integration-tests/test-utilities.ts +++ b/test/integration-tests/test-utilities.ts @@ -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} */ -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" : "")); } /**