Skip to content

Commit 56237d4

Browse files
committed
Propagate region if provided
1 parent 58a609a commit 56237d4

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

__tests__/index.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ describe("configureEnvironment", () => {
88
expect(env).toEqual({
99
AWS_ACCESS_KEY_ID: "test",
1010
AWS_SECRET_ACCESS_KEY: "test",
11+
AWS_REGION: "us-east-1",
12+
AWS_DEFAULT_REGION: "us-east-1",
1113
AWS_ENDPOINT_URL: "http://localhost.localstack.cloud:4566",
1214
AWS_ENDPOINT_URL_S3: "http://s3.localhost.localstack.cloud:4566",
1315
});
@@ -23,6 +25,8 @@ describe("configureEnvironment", () => {
2325
expect(env).toEqual({
2426
AWS_ACCESS_KEY_ID: "test",
2527
AWS_SECRET_ACCESS_KEY: "test",
28+
AWS_REGION: "us-east-1",
29+
AWS_DEFAULT_REGION: "us-east-1",
2630
AWS_ENDPOINT_URL: "http://foo.bar:4567",
2731
AWS_ENDPOINT_URL_S3: "http://foo.bar:4567",
2832
});
@@ -45,6 +49,8 @@ describe("configureEnvironment", () => {
4549
expect(env).toEqual({
4650
AWS_ACCESS_KEY_ID: "test",
4751
AWS_SECRET_ACCESS_KEY: "test",
52+
AWS_REGION: "us-east-1",
53+
AWS_DEFAULT_REGION: "us-east-1",
4854
AWS_ENDPOINT_URL: "http://localhost.localstack.cloud:4566",
4955
AWS_ENDPOINT_URL_S3: "http://s3.localhost.localstack.cloud:4566",
5056
});
@@ -60,6 +66,8 @@ describe("configureEnvironment", () => {
6066
AWS_ACCESS_KEY_ID: "test",
6167
AWS_SECRET_ACCESS_KEY: "test",
6268
AWS_PROFILE: "my-profile",
69+
AWS_REGION: "us-east-1",
70+
AWS_DEFAULT_REGION: "us-east-1",
6371
AWS_ENDPOINT_URL: "http://localhost.localstack.cloud:4566",
6472
AWS_ENDPOINT_URL_S3: "http://s3.localhost.localstack.cloud:4566",
6573
});
@@ -75,6 +83,25 @@ describe("configureEnvironment", () => {
7583
expect(env).toEqual({
7684
AWS_ACCESS_KEY_ID: "something",
7785
AWS_SECRET_ACCESS_KEY: "else",
86+
AWS_REGION: "us-east-1",
87+
AWS_DEFAULT_REGION: "us-east-1",
88+
AWS_ENDPOINT_URL: "http://localhost.localstack.cloud:4566",
89+
AWS_ENDPOINT_URL_S3: "http://s3.localhost.localstack.cloud:4566",
90+
});
91+
});
92+
93+
test("region overriding", () => {
94+
const env = {
95+
AWS_REGION: "eu-central-1",
96+
AWS_DEFAULT_REGION: "eu-central-1",
97+
};
98+
const allowListStr = "AWS_REGION,AWS_DEFAULT_REGION";
99+
configureEnvironment(env, allowListStr);
100+
expect(env).toEqual({
101+
AWS_ACCESS_KEY_ID: "test",
102+
AWS_SECRET_ACCESS_KEY: "test",
103+
AWS_REGION: "eu-central-1",
104+
AWS_DEFAULT_REGION: "eu-central-1",
78105
AWS_ENDPOINT_URL: "http://localhost.localstack.cloud:4566",
79106
AWS_ENDPOINT_URL_S3: "http://s3.localhost.localstack.cloud:4566",
80107
});

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ const configureEnvironment = (env, allowListStr) => {
5656
env.AWS_ACCESS_KEY_ID = env.AWS_ACCESS_KEY_ID || "test";
5757
env.AWS_SECRET_ACCESS_KEY = env.AWS_SECRET_ACCESS_KEY || "test";
5858

59+
// take region information from the environment if allowlisted
60+
env.AWS_REGION = env.AWS_REGION || "us-east-1";
61+
env.AWS_DEFAULT_REGION = env.AWS_DEFAULT_REGION || env.AWS_REGION;
62+
5963
// Explicitly set AWS_ENDPOINT_URL* to configure network access to LocalStack
6064
// This _must_ use localhost.localstack.cloud as we require valid subdomains of these paths to
6165
// resolve. Unfortunately though `curl` seems to support subdomains of localhost, the CDK does not.

0 commit comments

Comments
 (0)