Search code examples
node.jsreactjsamazon-web-servicesaws-ssm

AWS creds error when making calls from local react app "Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1"


I'm getting the following error when running my react app locally which make an api request to AWS via the AWS-SDK:

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

I've tried:

This is how I'm making the request:

import AWS from 'aws-sdk';
import { useState, useEffect } from 'react';

const ssm = new AWS.SSM({ region: 'eu-west-1' });

export const useFetchParams = (initialValue) => {
    const [result, setResult] = useState(initialValue);

    useEffect(() => {
        const params = {
            Path: '/',
            MaxResults: '2',
            Recursive: true,
            WithDecryption: true
        };

        ssm.getParametersByPath(params, function (err, data) {
            if (err) console.log(err, err.stack);
            else setResult(data);
        });
    }, []);

    return result;
};

export default useFetchParams;

Any help would be massively appreciated. Thanks.


Solution

  • The error states that credentials are missing so it is an authentication issue, you can try setting the accessKeyId and secretAccessKey or the credentials fields directly on the SSM constructor.

    So simply maintain your code as is, just make the following change:

    // From
    const ssm = new AWS.SSM({ region: 'eu-west-1' });
    
    // To
    const ssm = new AWS.SSM({
        region: 'eu-west-1',
        accessKeyId: 'your-access-key',
        secretAccessKey: 'your-secret-key'
    });
    
    // Or To
    const ssm = new AWS.SSM({
        region: 'eu-west-1',
        credentials: {
            accessKeyId: 'your-access-key',
            secretAccessKey: 'your-secret-key'
        }
    });