-
-
Notifications
You must be signed in to change notification settings - Fork 203
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
LocalstackContainer API enhancement #702
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,4 +69,18 @@ describe("LocalStackContainer", () => { | |
await container.stop(); | ||
await awsCliInDockerNetwork.stop(); | ||
}); | ||
|
||
it("should use access environment variables and default creds", async () => { | ||
const container = await new LocalstackContainer() | ||
.withEnvironment({ | ||
DEFAULT_REGION: "eu-west-3", | ||
}) | ||
.start(); | ||
|
||
expect(container.getRegion()).toBe("eu-west-3"); | ||
expect(container.getAccessKey()).toBe("test"); | ||
expect(container.getSecretKey()).toBe("test"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The container is mapping the environment variables to these getter methods, but this test is not checking that LS is actually using them. From the deprecation notices in the docs I get the impression they're not being used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think you're right... I see nothing in current documentation referencing these... Here again, I tried to reproduce the behavior of the test containers-java/local stack module, but this may be inappropriate. |
||
|
||
await container.stop(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,10 @@ import { AbstractStartedContainer, GenericContainer, log, StartedTestContainer, | |
|
||
export const LOCALSTACK_PORT = 4566; | ||
|
||
const DEFAULT_REGION = "us-east-1"; | ||
const DEFAULT_AWS_ACCESS_KEY_ID = "test"; | ||
const DEFAULT_AWS_SECRET_ACCESS_KEY = "test"; | ||
|
||
export class LocalstackContainer extends GenericContainer { | ||
constructor(image = "localstack/localstack:2.2.0") { | ||
super(image); | ||
|
@@ -50,4 +54,30 @@ export class StartedLocalStackContainer extends AbstractStartedContainer { | |
public getConnectionUri(): string { | ||
return `http://${this.getHost()}:${this.getPort().toString()}`; | ||
} | ||
|
||
/** | ||
* Provides a default region that is preconfigured to communicate with a given simulated service. | ||
* @returns A default region | ||
*/ | ||
public getRegion(): string { | ||
return this.startedTestContainer.getEnvironment()["DEFAULT_REGION"] || DEFAULT_REGION; | ||
} | ||
|
||
/** | ||
* Provides a default access key that is preconfigured to communicate with a given simulated service. | ||
* <a href="https://github.com/localstack/localstack/blob/master/doc/interaction/README.md?plain=1#L32">AWS Access Key</a> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm getting a 404 for these URLs. I also couldn't find reference to these environment variables in the LS config There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I blindly copy/paste here the comments coming from testcontainers-java/localstack |
||
* @returns A default access key | ||
*/ | ||
public getAccessKey(): string { | ||
return this.startedTestContainer.getEnvironment()["AWS_ACCESS_KEY_ID"] || DEFAULT_AWS_ACCESS_KEY_ID; | ||
} | ||
|
||
/** | ||
* Provides a default secret key that is preconfigured to communicate with a given simulated service. | ||
* <a href="https://github.com/localstack/localstack/blob/master/doc/interaction/README.md?plain=1#L32">AWS Secret Key</a> | ||
* @returns A default secret key | ||
*/ | ||
public getSecretKey(): string { | ||
return this.startedTestContainer.getEnvironment()["AWS_SECRET_ACCESS_KEY"] || DEFAULT_AWS_SECRET_ACCESS_KEY; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does the
DEFAULT_REGION
convention come from? I had a quick look at the docs and found https://docs.localstack.cloud/references/configuration/#legacy, which says that it's no longer supported.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think you're right. Many things have changed with 3.x and I should have refreshed my knowledge. The point is the default image is still
localstack/localstack:2.2.0
. As multi-region has been introduced incrementally, this may not affect the module, but it may be nice to upgrade to 3.x to definitely get rid of this question. What do you think?