AWS JS SDK V3 (Lambda module) - Unable to connect to instance metadata service

偶尔善良 提交于 2020-01-25 09:45:09

问题


I was previously using the all-in-one aws-sdk npm module (https://www.npmjs.com/package/aws-sdk) to invoke an AWS Lambda function, and for that the following code had been working well:

        //Some code to get "credentials"
        ...
        const AWS = require('aws-sdk');
        const lambda = new AWS.Lambda({
            accessKeyId: credentials.accessKeyId,
            secretAccessKey: credentials.secretAccessKey,
            region: Config.REGION
        });
        lambda.invoke(pullParams, (err, data) =>
            //I would do something with data
        );
        ...

Now, taking a cue from https://github.com/aws/aws-sdk-js-v3, I wish to use to modularised @aws-sdk/client-lambda-node, since it is the only class that I need in my project. Thus, I have changed my code (as suggested here: https://github.com/aws/aws-sdk-js-v3/tree/master/packages/client-lambda-node#usage) like so:

        import * as AWS from "@aws-sdk/client-lambda-node/Lambda";
        /*
          I believe there is a typo in the form of 
          "
           import * as AWS from "@aws-sdk/@aws-sdk/client-lambda-node/Lambda";
          "
          at the original page
        */
        ...
        //Some code to get the same "credentials" as above
        const lambda = new AWS.Lambda({
            accessKeyId: credentials.accessKeyId,
            secretAccessKey: credentials.secretAccessKey,
            region: Config.REGION
        });
        lambda.invokeAsync(pullParams, (err, data) =>
            //I want to do something with err / data
        );
        ...

For what its worth, this is inside a ReactJS app (though I'm sure thats not relevant). Trying the above code with version 0.1.0-preview.5 inside a browser (where it worked earlier) perpetually gives me

  1. http://169.254.169.254/latest/meta-data/iam/security-credentials/ net::ERR_CONNECTION_TIMED_OUT
  2. Error: Unable to connect to instance metadata service (I guess related to (1))

Is the library unstable for use, or am I doing something wrong

来源:https://stackoverflow.com/questions/56472155/aws-js-sdk-v3-lambda-module-unable-to-connect-to-instance-metadata-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!