【问题标题】: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"从本地反应应用程序进行调用时出现 AWS 凭据错误“配置中缺少凭据,如果使用 AWS_CONFIG_FILE,请设置 AWS_SDK_LOAD_CONFIG=1”
【发布时间】:2020-12-04 19:02:04
【问题描述】:

我在本地运行我的 react 应用程序时遇到以下错误,该应用程序通过 AWS-SDK 向 AWS 发出 api 请求:

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

我试过了:

这就是我提出请求的方式:

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;

任何帮助将不胜感激。谢谢。

【问题讨论】:

    标签: node.js reactjs amazon-web-services aws-ssm


    【解决方案1】:

    错误表明缺少凭据,因此这是一个身份验证问题,您可以尝试直接在 SSM 构造函数上设置 accessKeyIdsecretAccessKeycredentials 字段。

    所以只需按原样维护您的代码,只需进行以下更改:

    // 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'
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-28
      • 1970-01-01
      • 2020-10-07
      • 1970-01-01
      • 1970-01-01
      • 2022-01-12
      • 1970-01-01
      • 2020-05-12
      相关资源
      最近更新 更多