Skip to content

Honor AWS_ENDPOINT_URL_<SERVICE> env vars in generated Erlang clients#129

Open
vulkoingim wants to merge 4 commits into
aws-beam:masterfrom
vulkoingim:respect-aws_endpoint_url
Open

Honor AWS_ENDPOINT_URL_<SERVICE> env vars in generated Erlang clients#129
vulkoingim wants to merge 4 commits into
aws-beam:masterfrom
vulkoingim:respect-aws_endpoint_url

Conversation

@vulkoingim
Copy link
Copy Markdown

Depends on aws_beam_core:apply_endpoint_url_override

As a disclosure I have used a LLM to generate the code, but I have tested and verified that the generated erlang lib compiles and works against:

  • DynamoDB Local with AWS_ENDPOINT_URL_DYNAMODB
  • Real DynamoDB, no endpoint override
  • RustFS with AWS_ENDPOINT_URL_S3
  • Real S3

Generates do_request in the form:

 do_request(Client, Action, Input0, Options) ->
     Client1 = Client#{service => <<"dynamodb">>},
-    Host = build_host(<<"dynamodb">>, Client1),
-    URL = build_url(Host, Client1),
+    DefaultHost = build_host(<<"dynamodb">>, Client1),
+    {URL, Host} = aws_util:apply_endpoint_url_override(
+        build_url(DefaultHost, Client1), DefaultHost, <<"/">>,
+        <<"AWS_ENDPOINT_URL_DYNAMODB">>),
     Headers = [
         {<<"Host">>, Host},
         {<<"Content-Type">>, <<"application/x-amz-json-1.0">>},

Tested after generating the code, and patching the aws_util in aws-erlang.

cd aws-erlang
rebar3 compile
./test.escript
# and targeting local instances
export AWS_ENDPOINT_URL_S3=http://loclahost:9000
export AWS_ENDPOINT_URL_DYNAMODB=http://localhost:9001
#!/usr/bin/env escript
main(_) ->
    [code:add_pathz(E) || E <- filelib:wildcard("_build/default/lib/*/ebin")],
    {ok, _} = application:ensure_all_started(hackney),
    Env = fun(K) -> case os:getenv(K) of false -> halt(1); V -> list_to_binary(V) end end,
    Client = aws_client:make_client(Env("AWS_ACCESS_KEY_ID"), Env("AWS_SECRET_ACCESS_KEY"), Env("AWS_REGION")),
    io:format("DDB:  ~p~n", [aws_dynamodb:list_tables(Client, #{}, [])]),
    io:format("S3:   ~p~n", [aws_s3:list_buckets(Client, #{}, #{}, [])]).

Depends on aws_beam_core:apply_endpoint_url_override
Comment thread priv/post.erl.eex
Comment thread lib/aws_codegen/rest_service.ex Outdated
Comment thread lib/aws_codegen/post_service.ex Outdated
@onno-vos-dev
Copy link
Copy Markdown
Member

onno-vos-dev commented May 26, 2026

@vulkoingim I'll leave it up to you if you wanna address my comments. If I don't hear back from you by tomorrow, I'll merge it anyway but I think my comments would be cleaner. At least the obsolete util.ex code. Parsing these things is kinda brittle so the less places that deal with this sort of logic, the better.

vulkoingim and others added 3 commits May 27, 2026 10:11
Co-authored-by: Onno Vos <onno-vos-dev@users.noreply.github.com>
Co-authored-by: Onno Vos <onno-vos-dev@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants