Error: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1

Here is my lambda code

import AWS from "aws-sdk";
import response from "../../utils/response";

export const importProductsFile = async event => {
    // noinspection JSUnresolvedVariable
    if (!event.queryStringParameters || !event.queryStringParameters.name) {
        return response({ message: 'Bad request' }, 400);
    }

    const s3 = new AWS.S3({ region: 'eu-west-1' });
    try {
        const res = await s3.getSignedUrlPromise('putObject', {
            Bucket: 'static_buck',
            Key: `uploaded/${event.queryStringParameters.name}`,
            Expires: 60,
            ContentType: 'text/csv'
        });
        return response(res);
    } catch (e) {
        return response({ message: e.message || 'Unknown error' }, 500);
    }
}

Above lambda fails sometimes with "Missing credentials error", sometimes on timeout "Task timed out after 6.01 seconds". Error is thrown on the server, locally lambda is successfully invoked by serverless. Why sdk can't see aws credentials? Thank you

Upvotes: 1

Views: 712

Answers (1)

If this helps anyone, the problem was caused by webpack-dotenv plugin. It blocked global env variables, so aws-sdk couldn't access credentials.

Upvotes: 1

Related Questions