mattmartian

mattmartian

I have set up local stack within docker-compose so that I can do integration testing with s3, however with my setup I seem to be running into a nxdomain error that I can’t seem to figure out, below is my setup and some of my code for testing - am I missing something or doing something wrong? I know that I was originally using host networking but switched to bridge network

cross posted here: LocalStack Discuss Archive

error

#0 16.15 20:51:48.018 application=ex_aws domain=elixir file=lib/ex_aws/request.ex function=request_and_retry/7 line=78 mfa=ExAws.Request.request_and_retry/7 module=ExAws.Request pid=<0.591.0> [warn]  ExAws: HTTP ERROR: :nxdomain for URL: "http://localstack:4566/test-bucket/" ATTEMPT: 9
#0 18.28 
#0 18.28 20:51:50.156 application=ex_aws domain=elixir file=lib/ex_aws/request.ex function=request_and_retry/7 line=78 mfa=ExAws.Request.request_and_retry/7 module=ExAws.Request pid=<0.591.0> [warn]  ExAws: HTTP ERROR: :nxdomain for URL: "http://localstack:4566/test-bucket/" ATTEMPT: 10
#0 18.31 
#0 18.31 
#0 18.31   1) test get_object/2 get existing file from s3 (S3Test)
#0 18.31      test/s3_test.exs:12
#0 18.31      ** (ExAws.Error) ExAws Request Error!
#0 18.31      
#0 18.31      {:error, :nxdomain}
#0 18.31      
#0 18.31      code: ExAws.request!(ExAws.S3.put_bucket("test-bucket", "us-west-2"))
#0 18.31      stacktrace:
#0 18.31        (ex_aws 2.3.2) lib/ex_aws.ex:89: ExAws.request!/2
#0 18.31        test/s3_test.exs:28: (test)

config/test.exs

config :ex_aws,
  access_key_id: "test",
  secret_access_key: "test",
  region: "us-west-2"

config :ex_aws, :s3,
  scheme: "http://",
  host: "localstack",
  port: 4566,
  region: "us-west-2"

s3_test.exs

test "get existing file from s3" do
      # Create some random bytes to store in the file.
      contents = :crypto.strong_rand_bytes(100)

      # We set up an on_exit callback to empty and then delete the bucket
      # when the test exit, so that the next test has a clean slate.
      on_exit(fn ->
        "test-bucket"
        |> ExAws.S3.list_objects()
        |> ExAws.stream!()
        |> Enum.each(&ExAws.request!(ExAws.S3.delete_object("test-bucket", &1.key)))

        ExAws.request!(ExAws.S3.delete_bucket("test-bucket"))
      end)

      # Create bucket.
      ExAws.request!(ExAws.S3.put_bucket("test-bucket", "us-west-2"))

      # Upload a file.
      ExAws.request!(ExAws.S3.put_object("test-bucket", "my/random/file", contents))

      # Now, we run our code and assert on its behavior.
      {:ok, object} = S3Helper.get_object("test-bucket", "my/random/file")

      assert(Map.has_key?(object, :status_code) and object.status_code == 200)
    end

s3 logic

 @ex_aws_mod Application.compile_env(:tls_worker, [:test_doubles, :ex_aws], ExAws)

  def get_object(bucket, path) do
    ExAws.S3.get_object(bucket, path)
    |> @ex_aws_mod.request(region: Application.get_env(:ex_aws, :region))
  end

docker-compose

version: "3"
services:
  test:
    build:
      context: .
      dockerfile: Dockerfile.test
      args:
        MIX_ENV: test
        ENVIRONMENT: test
    volumes:
      - /app
    working_dir: /app
    command: MIX_ENV=test mix test
    depends_on:
      - localstack
    networks:
      - test
    stdin_open: true
    tty: true

  localstack:
    container_name: "${LOCALSTACK_DOCKER_NAME-localstack_main}"
    image: localstack/localstack
    environment:
      - AWS_DEFAULT_REGION="us-west-2"
      - SERVICES="s3"
      - EDGE_PORT="4566"
    networks:
      - test
    ports:
      - "4566:4566"  
    volumes:
      - "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
      - "/var/run/docker.sock:/var/run/docker.sock"

networks:
  test:
    driver: bridge

Showing Posts 1 to 2

jarlah

jarlah

This is not an answer to your problem, but personally I would rather try to use Testcontainers ceph container module. Instead of setting this up outside the tests

dimitarvp

dimitarvp

Have you noticed that you configure localstack be your host but the error in the terminal says that the domain/host is elixir?

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews