Closed marcingrabda closed 3 years ago
@marcingrabda is this related to this repo? Can you show how you're calling docker-lambda?
I trimmed my lambda down to:
const AWS = require('aws-sdk');
AWS.config.update({
region: 'us-east-1'
});
const s3 = new AWS.S3();
exports.handler = async function () {
let s3Bucket = process.env.S3_BUCKET;
let params = {
Bucket: s3Bucket,
Delimiter: '/'
};
let data = await s3.listObjectsV2(params).promise();
console.log(data);
}
I'm invoking it:
docker run -v $PROJECT_DIR:/var/task --rm -e S3_BUCKET=s3-bucket lambci/lambda:nodejs12.x index.handler {}
The error I'm getting is above.
It doesn't look like you're passing credentials in?
This works for me:
index.js
with the contents from your comment abovedocker run -v $PWD:/var/task --rm -e S3_BUCKET=mybucket \
-e AWS_SECRET_ACCESS_KEY -e AWS_ACCESS_KEY_ID -e AWS_SESSION_TOKEN \
lambci/lambda:nodejs12.x index.handler '{}'
Have you installed your own version of aws-sdk
? Do you have a node_modules
directory in your PROJECT_DIR
directory? It might be that you've got an out-of-date or buggy aws-sdk version?
Removing proxy configuration for Docker solved the problem. Thanks for your help.
Am I the only one getting the error below for every aws-sdk request?
2020-10-20T03:54:35.812Z 8debf246-54d9-1f6d-9a2f-d85fce49307f ERROR Uncaught Exception {"errorType":"TypeError [ERR_INVALID_CHAR]","errorMessage":"Invalid character in header content [\"x-aws-ec2-metadata-token\"]","code":"ERR_INVALID_CHAR","stack":["TypeError [ERR_INVALID_CHAR]: Invalid character in header content [\"x-aws-ec2-metadata-token\"]"," at ClientRequest.setHeader (_http_outgoing.js:473:3)"," at new ClientRequest (_http_client.js:203:14)"," at Object.request (http.js:42:10)"," at features.constructor.handleRequest (/var/task/node_modules/aws-sdk/lib/http/node.js:45:23)"," at sendRequest (/var/task/node_modules/aws-sdk/lib/util.js:887:12)"," at process._tickCallback (internal/process/next_tick.js:61:11)"]}