Giter Site home page Giter Site logo

All DynamoDB requests time out about ex_aws HOT 22 CLOSED

ex-aws avatar ex-aws commented on June 15, 2024
All DynamoDB requests time out

from ex_aws.

Comments (22)

jordi-chacon avatar jordi-chacon commented on June 15, 2024

I have fixed the timeout problem by sending the requests to https://dynamodb.eu-west-1.amazonaws.com:443/ instead.

Now I have a different problem. My requests failed to authenticate:

{error,
  {<<\"UnrecognizedClientException\">>,
   <<\"The security token included in the request is invalid.\">>}}

Debugging data:

url:
"https://dynamodb.eu-west-1.amazonaws.com:443/"

headers:
[{"Authorization",
  "AWS4-HMAC-SHA256 Credential=A....A/20150628/eu-west-1/dynamodb/aws4_request,SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date;x-amz-target,Signature=98........................c1"},
 {"host", "dynamodb.eu-west-1.amazonaws.com"},
 {"x-amz-date", "20150628T071505Z"},
 {"x-amz-target", "DynamoDB_20120810.CreateTable"},
 {"content-type", "application/x-amz-json-1.0"},
 {"x-amz-content-sha256", ""}]

config:
%{access_key_id: "A.......A",
  host: "dynamodb.eu-west-1.amazonaws.com",
  http_client: HTTPoison,
  json_codec: Poison,
  port: "443",
  region: "eu-west-1",
  scheme: "https://",
  secret_access_key: "k.....c"}

service:
:dynamodb

I have retrieved the key and the secret by curling http://169.254.169.254/latest/meta-data/iam/security-credentials/my_role and they are the same as the ones in the config. So that looks correct.

Any hints on what could be the problem?

from ex_aws.

benwilson512 avatar benwilson512 commented on June 15, 2024

Hey sorry I'm just not getting to this. So the issue related to the ports is partially my fault, partially not. HTTPs uses port 443 not port 80, so it isn't surprising that 80 didn't work. You could actually just leave off specifying the port entirely because then the URL would be simply "https://dynamodb.eu-west-1.amazonaws.com" and that will route to the correct port.

Basically, if the port is a numerical 80 then I don't put it as part of the URL at all. This is why the config may say port 80 for https but still work anyway, it gets stripped when the URLs are generated. This is clearly confusing behavior and I plan on doing something about it.

Unfortunately I'm not sure why that's the error you're getting. Try specifying the port as a numerical 80 which will drop it from the URL. I wonder if including the port number is munging up the AWS request signing process.

from ex_aws.

jordi-chacon avatar jordi-chacon commented on June 15, 2024

Hi!

Thanks for your reply.

I have specified the port as numerical 80 in config.exs as well as schema "http://". The url sent to ExAws.Request is now "http://dynamodb.eu-west-1.amazonaws.com/". So no port there as you said. Still getting the same error though :/

Is there anything else that I could debug that could hint us what the problem is?

from ex_aws.

benwilson512 avatar benwilson512 commented on June 15, 2024

Hey, I didn't intend for you to change the schema. HTTPoison (the http client library) is smart enough to use the correct port when the request is actually sent via HTTP. I simply want the port out of the signing process. Try with a schema of "https://" and a port of numerical 80.

On a different angle, the error you're getting seems to have to do with authentication, but isn't about signing errors. This seems to indicate that there may be permission issues with the IAM credentials. Have you used the AWS IAM simulator to determine if that role is able to execute the requests you want?

from ex_aws.

jordi-chacon avatar jordi-chacon commented on June 15, 2024

The IAM simulator says the operation is allowed. All DynamoDB operations are allowed by my policy. Furthermore, I have sent such requests from both inside the EC2 instance and from inside an ECS container via awscli.

from ex_aws.

benwilson512 avatar benwilson512 commented on June 15, 2024

Awesome good to know, we'll figure it out. Any luck with [schema: "https://", port: 80] ?

from ex_aws.

jordi-chacon avatar jordi-chacon commented on June 15, 2024

Just tried it, same problem.

from ex_aws.

benwilson512 avatar benwilson512 commented on June 15, 2024

Ok. I haven't had a chance to test much on the EU region, I'll ssh into an instance this afternoon and see if I can reproduce and determine the issues.

from ex_aws.

jordi-chacon avatar jordi-chacon commented on June 15, 2024

Thanks for your support!

I have tested running my Elixir application in an Ubuntu Server EC2 instance instead of inside an ECS container and the problem remains.

from ex_aws.

jordi-chacon avatar jordi-chacon commented on June 15, 2024

Interesting news.

Just did another test where, before starting the Elixir application, I run

export AWS_ACCESS_KEY_ID=A...L
export AWS_SECRET_ACCESS_KEY=b.....a

using the key and secret of my admin account. This worked. The requests to dynamodb worked just fine!

I have also tried exporting those environment variables with the key and secret I get from:

curl http://169.254.169.254/latest/meta-data/iam/security-credentials/myrole

This doesn't work. These credentials are actually the ones fetched by your library if I don't export the environment variables. So the problem seems to be with the key and the secret used.

from ex_aws.

benwilson512 avatar benwilson512 commented on June 15, 2024

Well that's certainly a relief on my end. Only thing I can recommend is to fiddle around with with the IAM simulator until you can reproduce the issue with the role / keys. Best of luck!

from ex_aws.

jordi-chacon avatar jordi-chacon commented on June 15, 2024

This is very strange.

Without running aws configure, this works:

aws dynamodb create-table --region eu-west-1 --table-name test_table --attribute-definitions AttributeName=uid,AttributeType=S --key-schema AttributeName=uid,KeyType=HASH --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1

If this works, shouldn't the requests coming from ex_aws also work?

from ex_aws.

benwilson512 avatar benwilson512 commented on June 15, 2024

Use set to determine if your environment variables are still set. aws will use those first.

from ex_aws.

jordi-chacon avatar jordi-chacon commented on June 15, 2024

I run this on a fresh new EC2 instance. I have not copied my admin credentials to this one.

from ex_aws.

benwilson512 avatar benwilson512 commented on June 15, 2024

So let me see if I can recap:

  • aws dynamodb $stuff: works
  • curl myrole + setting environment variables based on that result: doesn't work
  • ExAws configured to use instance_role: doesn't work

The fact that the second option doesn't work is super weird. Let me see if I can reproduce.

from ex_aws.

jordi-chacon avatar jordi-chacon commented on June 15, 2024

The recap is correct.

My EC2 instance is running ubuntu-trusty-14.04-amd64-server-20150325 (ami-47a23a30).

This EC2 instance has a role with the "Managed Policy" "AmazonDynamoDBFullAccess".

from ex_aws.

jordi-chacon avatar jordi-chacon commented on June 15, 2024

I'm a n00b in AWS, so I might be misunderstanding this statement, but it say that we should include a session token, which we don't seem to do.

"When you make a call using temporary security credentials, the call must include a session token, which is returned along with those temporary credentials. AWS uses the session token to validate the temporary security credentials."

http://docs.aws.amazon.com/STS/latest/UsingSTS/using-temp-creds.html

from ex_aws.

benwilson512 avatar benwilson512 commented on June 15, 2024

You may well be right there. This hasn't been a feature I've had a chance to test much I'm afraid. Investigating.

from ex_aws.

benwilson512 avatar benwilson512 commented on June 15, 2024

I've been able to reproduce. I believe you're correct about the cause. Fixing.

from ex_aws.

jordi-chacon avatar jordi-chacon commented on June 15, 2024

Cool!

Yes, I think we need to add a header called X-Amz-Security-Token with the value of the Token field in the security credentials.

from ex_aws.

benwilson512 avatar benwilson512 commented on June 15, 2024

This should be fixed on master now. Will do a release shortly. I've tested it myself, but please confirm that it looks ok on your end as well.

from ex_aws.

jordi-chacon avatar jordi-chacon commented on June 15, 2024

It works!!! 😃
Thank you so much for your dedication Ben.

from ex_aws.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.