Reputation: 1094
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
http://169.254.169.254/latest/meta-data/iam/security-credentials/ net::ERR_CONNECTION_TIMED_OUT
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
Upvotes: 4
Views: 3281
Reputation: 273
You have to pass your credentials using key credentials
.
Like:
const lambda = new AWS.Lambda({
credentials: {
accessKeyId: credentials.accessKeyId,
secretAccessKey: credentials.secretAccessKey,
},
region: Config.REGION
});
Or:
const lambda = new AWS.Lambda({
credentials,
region: Config.REGION
});
Upvotes: 6
Reputation: 2030
Yes, version 3 of the SDK is still in beta preview and they've stated that breaking changes are to be expected:
While the SDK is in preview, you may encounter bugs.
To answer your question, yes, it is absolutely unstable for production at the present time. Your specific issue is quite common and I was unable to get to the bottom of it either. My production work all uses v2 still.
Upvotes: 0