From 65bc3d61960b205707c9bf26506292c5b06242c4 Mon Sep 17 00:00:00 2001 From: VISHAL55UIET Date: Tue, 17 Nov 2026 22:32:38 +0530 Subject: [PATCH 1/3] Add AWS Emulator module --- .github/ISSUE_TEMPLATE/bug_report.yaml | 1 + .github/ISSUE_TEMPLATE/enhancement.yaml | 1 + .github/ISSUE_TEMPLATE/feature.yaml | 1 + .github/dependabot.yml | 1 + .github/labeler.yml | 4 + docs/modules/aws-emulator.md | 35 ++ mkdocs.yml | 1 + modules/aws-emulator/build.gradle | 9 + .../awsemulator/AwsEmulatorContainer.java | 304 ++++++++++++++++++ .../awsemulator/AwsEmulatorContainerTest.java | 133 ++++++++ 10 files changed, 490 insertions(+) create mode 100644 docs/modules/aws-emulator.md create mode 100644 modules/aws-emulator/build.gradle create mode 100644 modules/aws-emulator/src/main/java/org/testcontainers/awsemulator/AwsEmulatorContainer.java create mode 100644 modules/aws-emulator/src/test/java/org/testcontainers/awsemulator/AwsEmulatorContainerTest.java diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml index c31dd05e048..6c42a6fe1e6 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -15,6 +15,7 @@ body: options: - Core - ActiveMQ + - aws-emulator - Azure - Cassandra - ChromaDB diff --git a/.github/ISSUE_TEMPLATE/enhancement.yaml b/.github/ISSUE_TEMPLATE/enhancement.yaml index 9b9a06ecf6a..0bd4851b90b 100644 --- a/.github/ISSUE_TEMPLATE/enhancement.yaml +++ b/.github/ISSUE_TEMPLATE/enhancement.yaml @@ -15,6 +15,7 @@ body: options: - Core - ActiveMQ + - aws-emulator - Azure - Cassandra - ChromaDB diff --git a/.github/ISSUE_TEMPLATE/feature.yaml b/.github/ISSUE_TEMPLATE/feature.yaml index b655b4ac505..734e5503b2d 100644 --- a/.github/ISSUE_TEMPLATE/feature.yaml +++ b/.github/ISSUE_TEMPLATE/feature.yaml @@ -15,6 +15,7 @@ body: options: - Core - ActiveMQ + - aws-emulator - Azure - Cassandra - ChromaDB diff --git a/.github/dependabot.yml b/.github/dependabot.yml index d2908c1e2b5..b015db5dd85 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -62,6 +62,7 @@ updates: - package-ecosystem: "gradle" directories: - "/modules/activemq" + - "/modules/aws-emulator" - "/modules/azure" - "/modules/clickhouse" - "/modules/cockroachdb" diff --git a/.github/labeler.yml b/.github/labeler.yml index f4649bd7f99..bdf8dac1f15 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -23,6 +23,10 @@ - changed-files: - any-glob-to-any-file: - modules/activemq/**/* +"modules/aws-emulator": + - changed-files: + - any-glob-to-any-file: + - modules/aws-emulator/**/* "modules/azure": - changed-files: - any-glob-to-any-file: diff --git a/docs/modules/aws-emulator.md b/docs/modules/aws-emulator.md new file mode 100644 index 00000000000..35b6810a325 --- /dev/null +++ b/docs/modules/aws-emulator.md @@ -0,0 +1,35 @@ +# AWS Emulator + +!!! note +This module is INCUBATING. While it is ready for use and operational in the current version of Testcontainers, it is possible that it may receive breaking changes in the future. See [our contributing guidelines](/contributing/#incubating-modules) for more information on our incubating modules policy. + +Testcontainers module for [AWS Emulator](https://github.com/aws/aws-emulator). + +## AwsEmulatorContainer's usage examples + +You can start an AWS Emulator container instance from any Java application by using: + + +[AWS Emulator container](../../modules/aws-emulator/src/test/java/org/testcontainers/awsemulator/AwsEmulatorContainerTest.java) inside_block:container + + +The container automatically configures the recommended 2 GiB memory limit, disables usage telemetry by default, waits for the HTTPS `/__admin/health` endpoint, and extracts the generated PKCS12 truststore (`getTrustStorePath()`) and SigV4 credentials (`getAccessKey()`, `getSecretKey()`). + +## Adding this module to your project dependencies + +Add the following dependency to your `pom.xml`/`build.gradle` file: + +=== "Gradle" +```groovy +testImplementation "org.testcontainers:testcontainers-aws-emulator:{{latest_version}}" +``` + +=== "Maven" +```xml + + org.testcontainers + testcontainers-aws-emulator + {{latest_version}} + test + +``` diff --git a/mkdocs.yml b/mkdocs.yml index ae447212912..c3235eb9bec 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -77,6 +77,7 @@ nav: - modules/databases/trino.md - modules/databases/yugabytedb.md - modules/activemq.md + - modules/aws-emulator.md - modules/azure.md - modules/chromadb.md - modules/consul.md diff --git a/modules/aws-emulator/build.gradle b/modules/aws-emulator/build.gradle new file mode 100644 index 00000000000..75c54a06663 --- /dev/null +++ b/modules/aws-emulator/build.gradle @@ -0,0 +1,9 @@ +description = "Testcontainers :: AWS Emulator" + +dependencies { + api project(':testcontainers') + + testImplementation 'software.amazon.awssdk:s3:2.31.1' + testImplementation 'software.amazon.awssdk:sts:2.31.1' + testImplementation 'software.amazon.awssdk:url-connection-client:2.31.1' +} diff --git a/modules/aws-emulator/src/main/java/org/testcontainers/awsemulator/AwsEmulatorContainer.java b/modules/aws-emulator/src/main/java/org/testcontainers/awsemulator/AwsEmulatorContainer.java new file mode 100644 index 00000000000..ffdfe03ca11 --- /dev/null +++ b/modules/aws-emulator/src/main/java/org/testcontainers/awsemulator/AwsEmulatorContainer.java @@ -0,0 +1,304 @@ +package org.testcontainers.awsemulator; + +import com.github.dockerjava.api.command.InspectContainerResponse; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.images.builder.ImageFromDockerfile; +import org.testcontainers.utility.DockerImageName; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.InetAddress; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.UnknownHostException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.concurrent.Future; + +/** + * Testcontainers implementation for AWS Emulator. + *

+ * Supported images: {@code aws-emulator} (or built automatically from the official AWS Linux RPM package) + *

+ * Exposed ports: 9297 (HTTPS) + */ +public class AwsEmulatorContainer extends GenericContainer { + + static final int PORT = 9297; + + private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("aws-emulator"); + + private static final String DEFAULT_REGION = "us-east-1"; + + private static final long TWO_GIB_IN_BYTES = 2L * 1024 * 1024 * 1024; + + private static final String EMULATOR_DATA_DIR = "/home/emulator/.aws/emulator/" + PORT; + + private boolean telemetryEnabled = false; + + private boolean authEnabled = true; + + private long memoryLimitBytes = TWO_GIB_IN_BYTES; + + private String region = DEFAULT_REGION; + + private String accessKey; + + private String secretKey; + + private Path trustStorePath; + + /** + * Creates an {@link AwsEmulatorContainer} by building the image on-the-fly from the official + * Amazon Linux 2023 minimal base image and AWS Emulator RPM package. + */ + public AwsEmulatorContainer() { + super(createDefaultImage()); + initContainer(); + } + + /** + * Creates an {@link AwsEmulatorContainer} from a prebuilt Docker image name. + * + * @param dockerImageName image name to use for AWS Emulator + */ + public AwsEmulatorContainer(final String dockerImageName) { + this(DockerImageName.parse(dockerImageName)); + } + + /** + * Creates an {@link AwsEmulatorContainer} from a prebuilt {@link DockerImageName}. + * + * @param dockerImageName image name to use for AWS Emulator + */ + public AwsEmulatorContainer(final DockerImageName dockerImageName) { + super(dockerImageName); + dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); + initContainer(); + } + + private static Future createDefaultImage() { + String arch = System.getProperty("os.arch", "").toLowerCase(Locale.ROOT); + String rpmArch = (arch.contains("aarch64") || arch.contains("arm64")) ? "aarch64" : "x86_64"; + String rpmUrl = + "https://downloads.aws.com/aws-emulator/packages/aws-emulator/LTS/latest/aws-emulator-" + rpmArch + ".rpm"; + + return new ImageFromDockerfile("testcontainers/aws-emulator", false) + .withDockerfileFromBuilder(builder -> { + builder + .from("public.ecr.aws/amazonlinux/amazonlinux:2023-minimal") + .add(rpmUrl, "/tmp/aws-emulator.rpm") + .run( + "rpm -i /tmp/aws-emulator.rpm && rm /tmp/aws-emulator.rpm && mkdir -p /home/emulator && chown 1000 /home/emulator" + ) + .user("1000") + .env("HOME", "/home/emulator") + .expose(PORT) + .entryPoint("aws-emulator", "-b", "0.0.0.0") + .build(); + }); + } + + private void initContainer() { + withExposedPorts(PORT); + waitingFor( + Wait + .forHttp("/__admin/health") + .forPort(PORT) + .usingTls() + .allowInsecure() + .forStatusCode(200) + .forResponsePredicate("ok"::equals) + ); + } + + @Override + protected void configure() { + withEnv("EMULATOR_TELEMETRY", this.telemetryEnabled ? "on" : "off"); + withEnv("AWS_REGION", this.region); + withEnv("AWS_DEFAULT_REGION", this.region); + + List cmdArgs = new ArrayList<>(); + cmdArgs.add("-p"); + cmdArgs.add(String.valueOf(PORT)); + if (!this.authEnabled) { + cmdArgs.add("--auth"); + cmdArgs.add("off"); + } + withCommand(cmdArgs.toArray(new String[0])); + + withCreateContainerCmdModifier(cmd -> { + if (cmd.getHostConfig() != null) { + cmd.getHostConfig().withMemory(this.memoryLimitBytes).withMemorySwap(this.memoryLimitBytes); + } + }); + } + + @Override + protected void containerIsStarted(InspectContainerResponse containerInfo) { + extractTrustStore(); + if (this.authEnabled) { + extractCredentials(); + } + } + + private void extractTrustStore() { + try { + Path tempTrustStore = Files.createTempFile("aws-emulator-truststore-", ".p12"); + tempTrustStore.toFile().deleteOnExit(); + copyFileFromContainer(EMULATOR_DATA_DIR + "/truststore.p12", tempTrustStore.toAbsolutePath().toString()); + this.trustStorePath = tempTrustStore; + } catch (IOException e) { + throw new IllegalStateException("Failed to extract truststore.p12 from AWS Emulator container", e); + } + } + + private void extractCredentials() { + copyFileFromContainer( + EMULATOR_DATA_DIR + "/emulator_credentials", + inputStream -> { + try ( + BufferedReader reader = new BufferedReader( + new InputStreamReader(inputStream, StandardCharsets.UTF_8) + ) + ) { + String line; + while ((line = reader.readLine()) != null) { + String trimmed = line.trim(); + if (trimmed.startsWith("aws_access_key_id")) { + this.accessKey = extractIniValue(trimmed); + } else if (trimmed.startsWith("aws_secret_access_key")) { + this.secretKey = extractIniValue(trimmed); + } + } + } + return null; + } + ); + } + + private static String extractIniValue(String line) { + int idx = line.indexOf('='); + if (idx < 0 || idx == line.length() - 1) { + return null; + } + return line.substring(idx + 1).trim(); + } + + /** + * Enables or disables usage telemetry in the AWS Emulator (disabled by default). + * + * @param telemetryEnabled {@code true} to enable telemetry, {@code false} to disable + * @return this container instance + */ + public AwsEmulatorContainer withTelemetryEnabled(boolean telemetryEnabled) { + this.telemetryEnabled = telemetryEnabled; + return self(); + } + + /** + * Enables or disables SigV4 request signature verification (enabled by default). + * + * @param authEnabled {@code true} to require SigV4 authentication, {@code false} to disable + * @return this container instance + */ + public AwsEmulatorContainer withAuthEnabled(boolean authEnabled) { + this.authEnabled = authEnabled; + return self(); + } + + /** + * Sets the memory limit (and matching memory-swap limit) in bytes for the container. + * Defaults to 2 GiB as recommended by AWS Emulator. + * + * @param memoryLimitBytes memory limit in bytes (must be positive) + * @return this container instance + */ + public AwsEmulatorContainer withMemoryLimit(long memoryLimitBytes) { + if (memoryLimitBytes <= 0) { + throw new IllegalArgumentException("memoryLimitBytes must be greater than 0"); + } + this.memoryLimitBytes = memoryLimitBytes; + return self(); + } + + /** + * Sets the default AWS region for the emulator. + * + * @param region AWS region identifier (e.g., {@code us-east-1}) + * @return this container instance + */ + public AwsEmulatorContainer withRegion(String region) { + if (region == null || region.trim().isEmpty()) { + throw new IllegalArgumentException("region must not be null or empty"); + } + this.region = region.trim(); + return self(); + } + + /** + * Returns the HTTPS endpoint URI to configure on AWS SDK v2 clients. + * + * @return the HTTPS endpoint {@link URI} + */ + public URI getEndpoint() { + try { + String ipAddress = InetAddress.getByName(getHost()).getHostAddress(); + return new URI("https://" + ipAddress + ":" + getMappedPort(PORT)); + } catch (UnknownHostException | URISyntaxException e) { + throw new IllegalStateException("Cannot obtain endpoint URL", e); + } + } + + /** + * Returns the generated AWS access key ID for this emulator run, or {@code "test"} if auth is disabled. + * + * @return the AWS access key ID + */ + public String getAccessKey() { + return this.accessKey != null ? this.accessKey : "test"; + } + + /** + * Returns the generated AWS secret access key for this emulator run, or {@code "test"} if auth is disabled. + * + * @return the AWS secret access key + */ + public String getSecretKey() { + return this.secretKey != null ? this.secretKey : "test"; + } + + /** + * Returns the configured AWS region. + * + * @return the AWS region + */ + public String getRegion() { + return this.region; + } + + /** + * Returns the local path to the extracted PKCS12 truststore ({@code truststore.p12}) + * containing the emulator's self-signed TLS certificate. + * + * @return path to {@code truststore.p12} + */ + public Path getTrustStorePath() { + return this.trustStorePath; + } + + /** + * Returns the truststore type ({@code PKCS12}) for use with Java SSL configuration. + * + * @return {@code "PKCS12"} + */ + public String getTrustStoreType() { + return "PKCS12"; + } +} diff --git a/modules/aws-emulator/src/test/java/org/testcontainers/awsemulator/AwsEmulatorContainerTest.java b/modules/aws-emulator/src/test/java/org/testcontainers/awsemulator/AwsEmulatorContainerTest.java new file mode 100644 index 00000000000..fd8bd4ff408 --- /dev/null +++ b/modules/aws-emulator/src/test/java/org/testcontainers/awsemulator/AwsEmulatorContainerTest.java @@ -0,0 +1,133 @@ +package org.testcontainers.awsemulator; + +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; +import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; +import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption; +import software.amazon.awssdk.http.TlsTrustManagersProvider; +import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.s3.S3Client; +import software.amazon.awssdk.services.s3.model.CreateBucketRequest; +import software.amazon.awssdk.services.s3.model.ListBucketsResponse; +import software.amazon.awssdk.services.sts.StsClient; +import software.amazon.awssdk.services.sts.model.GetCallerIdentityResponse; + +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.KeyStore; + +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactory; + +import static org.assertj.core.api.Assertions.assertThat; + +class AwsEmulatorContainerTest { + + @Test + void testS3OperationsWithExtractedTrustStoreAndCredentials() throws Exception { + try ( + // container { + AwsEmulatorContainer emulator = new AwsEmulatorContainer() + // } + ) { + emulator.start(); + + assertThat(emulator.getEndpoint().toString()).startsWith("https://"); + assertThat(emulator.getTrustStorePath()).exists(); + assertThat(emulator.getAccessKey()).isNotBlank(); + assertThat(emulator.getSecretKey()).isNotBlank(); + + TlsTrustManagersProvider trustManagersProvider = createTrustManagersProvider( + emulator.getTrustStorePath(), + emulator.getTrustStoreType() + ); + + try ( + S3Client s3 = S3Client + .builder() + .endpointOverride(emulator.getEndpoint()) + .credentialsProvider( + StaticCredentialsProvider.create( + AwsBasicCredentials.create(emulator.getAccessKey(), emulator.getSecretKey()) + ) + ) + .region(Region.of(emulator.getRegion())) + .overrideConfiguration(config -> { + config.putAdvancedOption(SdkAdvancedClientOption.DISABLE_HOST_PREFIX_INJECTION, true); + }) + .httpClientBuilder( + UrlConnectionHttpClient.builder().tlsTrustManagersProvider(trustManagersProvider) + ) + .build() + ) { + s3.createBucket(CreateBucketRequest.builder().bucket("test-bucket").build()); + ListBucketsResponse buckets = s3.listBuckets(); + assertThat(buckets.buckets()).extracting("name").contains("test-bucket"); + } + } + } + + @Test + void testStsCallerIdentity() throws Exception { + try (AwsEmulatorContainer emulator = new AwsEmulatorContainer().withRegion("us-west-2")) { + emulator.start(); + + TlsTrustManagersProvider trustManagersProvider = createTrustManagersProvider( + emulator.getTrustStorePath(), + emulator.getTrustStoreType() + ); + + try ( + StsClient sts = StsClient + .builder() + .endpointOverride(emulator.getEndpoint()) + .credentialsProvider( + StaticCredentialsProvider.create( + AwsBasicCredentials.create(emulator.getAccessKey(), emulator.getSecretKey()) + ) + ) + .region(Region.of(emulator.getRegion())) + .overrideConfiguration(config -> { + config.putAdvancedOption(SdkAdvancedClientOption.DISABLE_HOST_PREFIX_INJECTION, true); + }) + .httpClientBuilder( + UrlConnectionHttpClient.builder().tlsTrustManagersProvider(trustManagersProvider) + ) + .build() + ) { + GetCallerIdentityResponse identity = sts.getCallerIdentity(); + assertThat(identity.account()).isEqualTo("000000000000"); + assertThat(identity.arn()).contains("emulator"); + } + } + } + + @Test + void testWithAuthDisabled() throws Exception { + try ( + AwsEmulatorContainer emulator = new AwsEmulatorContainer() + .withAuthEnabled(false) + .withTelemetryEnabled(false) + ) { + emulator.start(); + + assertThat(emulator.getAccessKey()).isEqualTo("test"); + assertThat(emulator.getSecretKey()).isEqualTo("test"); + assertThat(emulator.getEnvMap()).containsEntry("EMULATOR_TELEMETRY", "off"); + } + } + + private static TlsTrustManagersProvider createTrustManagersProvider(Path trustStorePath, String trustStoreType) + throws Exception { + KeyStore keyStore = KeyStore.getInstance(trustStoreType); + try (InputStream is = Files.newInputStream(trustStorePath)) { + keyStore.load(is, new char[0]); + } + TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); + tmf.init(keyStore); + TrustManager[] trustManagers = tmf.getTrustManagers(); + return () -> trustManagers; + } +} From ea0d46e397d1f020264896ea4e995dce3b805d62 Mon Sep 17 00:00:00 2001 From: VISHAL55UIET Date: Tue, 17 Nov 2026 23:03:51 +0530 Subject: [PATCH 2/3] Address CodeRabbit review feedback --- docs/modules/aws-emulator.md | 1 - .../awsemulator/AwsEmulatorContainer.java | 53 ++++++++++++++----- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/docs/modules/aws-emulator.md b/docs/modules/aws-emulator.md index 35b6810a325..b488698c20b 100644 --- a/docs/modules/aws-emulator.md +++ b/docs/modules/aws-emulator.md @@ -14,7 +14,6 @@ You can start an AWS Emulator container instance from any Java application by us The container automatically configures the recommended 2 GiB memory limit, disables usage telemetry by default, waits for the HTTPS `/__admin/health` endpoint, and extracts the generated PKCS12 truststore (`getTrustStorePath()`) and SigV4 credentials (`getAccessKey()`, `getSecretKey()`). - ## Adding this module to your project dependencies Add the following dependency to your `pom.xml`/`build.gradle` file: diff --git a/modules/aws-emulator/src/main/java/org/testcontainers/awsemulator/AwsEmulatorContainer.java b/modules/aws-emulator/src/main/java/org/testcontainers/awsemulator/AwsEmulatorContainer.java index ffdfe03ca11..f15c41ffe5c 100644 --- a/modules/aws-emulator/src/main/java/org/testcontainers/awsemulator/AwsEmulatorContainer.java +++ b/modules/aws-emulator/src/main/java/org/testcontainers/awsemulator/AwsEmulatorContainer.java @@ -1,6 +1,7 @@ package org.testcontainers.awsemulator; import com.github.dockerjava.api.command.InspectContainerResponse; +import org.testcontainers.DockerClientFactory; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.images.builder.ImageFromDockerfile; @@ -23,10 +24,10 @@ /** * Testcontainers implementation for AWS Emulator. - *

- * Supported images: {@code aws-emulator} (or built automatically from the official AWS Linux RPM package) - *

- * Exposed ports: 9297 (HTTPS) + * + *

Supported images: {@code aws-emulator} (or built automatically from the official AWS Linux RPM package) + * + *

Exposed ports: 9297 (HTTPS) */ public class AwsEmulatorContainer extends GenericContainer { @@ -34,6 +35,19 @@ public class AwsEmulatorContainer extends GenericContainer private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("aws-emulator"); + private static final String BASE_IMAGE = + "public.ecr.aws/amazonlinux/amazonlinux@sha256:158a9044f9dc0777f098b76c8b54346f6ed4560b9a6a416dec7a5ba3bc483af4"; + + private static final String RPM_URL_X86_64 = + "https://downloads.aws.com/aws-emulator/packages/aws-emulator/LTS/latest/aws-emulator-x86_64.rpm"; + + private static final String RPM_SHA256_X86_64 = "0aa130ff811add64826c6811ec714e375d4a7891d08976ae57bdb6ee645724ee"; + + private static final String RPM_URL_AARCH64 = + "https://downloads.aws.com/aws-emulator/packages/aws-emulator/LTS/latest/aws-emulator-aarch64.rpm"; + + private static final String RPM_SHA256_AARCH64 = "38e2069c656429eaa023fdc807a49c02a48acff77f090f068ccdc9fa0a7c4fe4"; + private static final String DEFAULT_REGION = "us-east-1"; private static final long TWO_GIB_IN_BYTES = 2L * 1024 * 1024 * 1024; @@ -84,18 +98,19 @@ public AwsEmulatorContainer(final DockerImageName dockerImageName) { } private static Future createDefaultImage() { - String arch = System.getProperty("os.arch", "").toLowerCase(Locale.ROOT); - String rpmArch = (arch.contains("aarch64") || arch.contains("arm64")) ? "aarch64" : "x86_64"; - String rpmUrl = - "https://downloads.aws.com/aws-emulator/packages/aws-emulator/LTS/latest/aws-emulator-" + rpmArch + ".rpm"; + boolean isArm64 = isArm64Daemon(); + String rpmUrl = isArm64 ? RPM_URL_AARCH64 : RPM_URL_X86_64; + String expectedSha256 = isArm64 ? RPM_SHA256_AARCH64 : RPM_SHA256_X86_64; return new ImageFromDockerfile("testcontainers/aws-emulator", false) .withDockerfileFromBuilder(builder -> { builder - .from("public.ecr.aws/amazonlinux/amazonlinux:2023-minimal") + .from(BASE_IMAGE) .add(rpmUrl, "/tmp/aws-emulator.rpm") .run( - "rpm -i /tmp/aws-emulator.rpm && rm /tmp/aws-emulator.rpm && mkdir -p /home/emulator && chown 1000 /home/emulator" + "echo \"" + + expectedSha256 + + " /tmp/aws-emulator.rpm\" | sha256sum -c - && rpm -i /tmp/aws-emulator.rpm && rm /tmp/aws-emulator.rpm && mkdir -p /home/emulator && chown 1000 /home/emulator" ) .user("1000") .env("HOME", "/home/emulator") @@ -105,6 +120,20 @@ private static Future createDefaultImage() { }); } + private static boolean isArm64Daemon() { + String arch = null; + try { + arch = DockerClientFactory.instance().client().infoCmd().exec().getArchitecture(); + } catch (Exception ignored) { + // Fall back to JVM architecture if Docker daemon info cannot be queried + } + if (arch == null || arch.trim().isEmpty()) { + arch = System.getProperty("os.arch", ""); + } + String normalized = arch.toLowerCase(Locale.ROOT); + return normalized.contains("aarch64") || normalized.contains("arm64"); + } + private void initContainer() { withExposedPorts(PORT); waitingFor( @@ -250,9 +279,9 @@ public AwsEmulatorContainer withRegion(String region) { public URI getEndpoint() { try { String ipAddress = InetAddress.getByName(getHost()).getHostAddress(); - return new URI("https://" + ipAddress + ":" + getMappedPort(PORT)); + return new URI("https", null, ipAddress, getMappedPort(PORT), null, null, null); } catch (UnknownHostException | URISyntaxException e) { - throw new IllegalStateException("Cannot obtain endpoint URL", e); + throw new IllegalStateException("Failed to build AWS Emulator endpoint URI", e); } } From ebf739f6fb67386aecdfc014cb3d8eff69b06df8 Mon Sep 17 00:00:00 2001 From: VISHAL55UIET Date: Tue, 17 Nov 2026 23:13:23 +0530 Subject: [PATCH 3/3] Indent dependency blocks inside tabs in docs --- docs/modules/aws-emulator.md | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/docs/modules/aws-emulator.md b/docs/modules/aws-emulator.md index b488698c20b..94fa0dd8218 100644 --- a/docs/modules/aws-emulator.md +++ b/docs/modules/aws-emulator.md @@ -19,16 +19,18 @@ The container automatically configures the recommended 2 GiB memory limit, disab Add the following dependency to your `pom.xml`/`build.gradle` file: === "Gradle" -```groovy -testImplementation "org.testcontainers:testcontainers-aws-emulator:{{latest_version}}" -``` + + ```groovy + testImplementation "org.testcontainers:testcontainers-aws-emulator:{{latest_version}}" + ``` === "Maven" -```xml - - org.testcontainers - testcontainers-aws-emulator - {{latest_version}} - test - -``` + + ```xml + + org.testcontainers + testcontainers-aws-emulator + {{latest_version}} + test + + ```