Ex_aws file upload error

i am trying to upload file from app running on EC2 to s3. i am getting this error.
i checked my aws keys. they are fine.
i understand i have to give some permissions to ec2 server to access s3 bucket. but dont know how to do it.

07:37:17.818 [error] GenServer ExAws.Config.AuthCache terminating
** (RuntimeError) Instance Meta Error: HTTP response status code 404

Please check AWS EC2 IAM role.

    (ex_aws) lib/ex_aws/instance_meta.ex:20: ExAws.InstanceMeta.request/2
    (ex_aws) lib/ex_aws/instance_meta.ex:58: ExAws.InstanceMeta.instance_role_credentials/1
    (ex_aws) lib/ex_aws/instance_meta.ex:64: ExAws.InstanceMeta.security_credentials/1
    (ex_aws) lib/ex_aws/config/auth_cache.ex:58: ExAws.Config.AuthCache.refresh_config/2
    (ex_aws) lib/ex_aws/config/auth_cache.ex:33: ExAws.Config.AuthCache.handle_call/3
    (stdlib) gen_server.erl:636: :gen_server.try_handle_call/4
    (stdlib) gen_server.erl:665: :gen_server.handle_msg/6
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message (from #PID<0.576.0>): {:refresh_config, %{access_key_id: [{:system, "AWS_ACCESS_KEY_ID"}, :instance_role], host: "s3.amazonaws.com", http_client: ExAws.Request.Hackney, json_codec: Poison, port: 443, region: "us-east-1", retries: [max_attempts: 10, base_backoff_in_ms: 10, max_backoff_in_ms: 10000], scheme: "https://", secret_access_key: [{:system, "AWS_SECRET_ACCESS_KEY"}, :instance_role]}}
07:37:17.863 [error] #PID<0.576.0> running HelloWeb.Endpoint terminated
Server: apis.domain.com:4004 (https)
Request: POST /api/registration/ors1
** (exit) exited in: GenServer.call(ExAws.Config.AuthCache, {:refresh_config, %{access_key_id: [{:system, "AWS_ACCESS_KEY_ID"}, :instance_role], host: "s3.amazonaws.com", http_client: ExAws.Request.Hackney, json_codec: Poison, port: 443, region: "us-east-1", retries: [max_attempts: 10, base_backoff_in_ms: 10, max_backoff_in_ms: 10000], scheme: "https://", secret_access_key: [{:system, "AWS_SECRET_ACCESS_KEY"}, :instance_role]}}, 30000)
    ** (EXIT) an exception was raised:
        ** (RuntimeError) Instance Meta Error: HTTP response status code 404

Please check AWS EC2 IAM role.

            (ex_aws) lib/ex_aws/instance_meta.ex:20: ExAws.InstanceMeta.request/2
            (ex_aws) lib/ex_aws/instance_meta.ex:58: ExAws.InstanceMeta.instance_role_credentials/1
            (ex_aws) lib/ex_aws/instance_meta.ex:64: ExAws.InstanceMeta.security_credentials/1
            (ex_aws) lib/ex_aws/config/auth_cache.ex:58: ExAws.Config.AuthCache.refresh_config/2
            (ex_aws) lib/ex_aws/config/auth_cache.ex:33: ExAws.Config.AuthCache.handle_call/3
            (stdlib) gen_server.erl:636: :gen_server.try_handle_call/4
            (stdlib) gen_server.erl:665: :gen_server.handle_msg/6
            (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3

You have to go in to IAM, and make sure the user that is associated with the credentials you are using, has the necessary s3 permissions.

1 Like

This error message is a little old, you should consider upgrading your ExAws. Basically what’s happening here is that ExAws isn’t finding any auth credentials, and so is trying to use the EC2 IAM role. That isn’t working either, so it’s exploding. I’d double check how you’re trying to load your credentials.

1 Like