aws-sdk-js: Request hangs on missing credentials


When I attempt to run request without an AWS credentials it just hangs infinitely.

I’d expect it to crash immediately with Missing credentials error.

Why it’s not the case?

e.g. following will just hang if run without any AWS creds setup:

const { Lambda } = require('aws-sdk');
const lambda = new Lambda();

lambda
  .invoke({ FunctionName: 'foo' })
  .promise()
  .then(
    data => console.log('Success', data),
    error => console.log('Error', data)
  );

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 4
  • Comments: 28 (13 by maintainers)

Most upvoted comments

@medikoo have you tried connectTimeout? That worked for me last time I checked this issue

EDIT: connectTimeout, not connectionTimeout

@ajredniwja

Regarding your statement:

I understand the concern there and it can be frustrating at times. I believe this is not necessarily a bug but the behavior of the SDK which can be enhanced. Hence would like to mark it as a feature request.

I’m not sure if anyone has mentioned/encountered this, but when I run the SDK with invalid credentials a few times, it occasionally does error with MissingCredentials, but usually hangs. This definitely would classify as a bug to me, if the behaviour is inconsistent. It should either hang consistently or throw an error consistently.

@pauloprestes I tried this on node v13.11 and SDK versions v2.655.0 and v2.656.0 but it still hangs

Code to replicate

/tmp $ time node index.js
Error: connect ETIMEDOUT 169.254.169.254:80
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)

real	2m32.504s
user	0m0.245s
sys	0m0.041s

How can you overwrite the timeout? I tried:

  aws.MetadataService.httpOptions = { timeout: 100 };

But it’s still taking ~2.5min to fail

Hey @ajredniwja I’ve seen this behavior happening on lambdas with high volume of invocations, like 1 on 1k invocations, maybe even less. Generally it is easy solved by adding a timeout and retries.

Thanks @ajredniwja I’ll try to look into that

aws-sdk-go checks if the timeout is set to 0 for the ec2metada and overrides it to 1 second, to solve this issue, maybe we could do the same here? https://github.com/aws/aws-sdk-go/blob/0c96ad536ae45eb23a2b5ed2b4ef9a840eec6f6e/aws/ec2metadata/service.go#L76

on aws-sdk-js, it is always set to 0. https://github.com/aws/aws-sdk-js/blob/2d1be139f5d95b4846e5c99a474f08a7c093c440/lib/metadata_service.js#L38

Encountered this error with a typo in my access credential properties, cost a lot of time trying to work out the issue because the SDK never reported an error.