AWS Missing credentials when i try send something to my S3 Bucket (Node.js)

后端 未结 7 871
眼角桃花
眼角桃花 2020-12-02 16:51

Hei!

I\'m having this issue since yesterday, and I\'m having trouble for find a solution.

I\'m trying to send somethings to my S3 bucket, but this message ap

相关标签:
7条回答
  • 2020-12-02 17:15

    I had a similar issue when trying to load the config file from anywhere other than the root directory.

    I was able to load the json file natively in node, then just pass the object that was parsed to AWS.config.update()

    import AWS from 'aws-sdk'
    import config from '../aws.json' 
    AWS.config.update(config);
    
    0 讨论(0)
  • 2020-12-02 17:16

    This resolved my issue .

    1. Used the sample code from the Cognito Console and added it to the of the document.

    2. Enabled Unauthenticated access on the identity pool.

    Most important

    1. Fixed the Trust Relationship policy in the unauth role so the Cognito Service could assume the role.

    2. Do not hard code credential in the file .

    0 讨论(0)
  • 2020-12-02 17:24

    Try hardcoding your params and see if you get the error again :

    AWS.config.update({
        accessKeyId: "YOURKEY",
        secretAccessKey: "YOURSECRET",
        "region": "sa-east-1"   <- If you want send something to your bucket, you need take off this settings, because the S3 are global. 
    }); // for simplicity. In prod, use loadConfigFromFile, or env variables
    
    var s3 = new AWS.S3();
    var params = {
        Bucket: 'makersquest',
        Key: 'mykey.txt',
        Body: "HelloWorld"
    };
    s3.putObject(params, function (err, res) {
        if (perr) {
            console.log("Error uploading data: ", err);
        } else {
            console.log("Successfully uploaded data to myBucket/myKey");
        }
    });
    

    Good resource here

    0 讨论(0)
  • 2020-12-02 17:33

    Try changing the user in my aws config file from a specific user to [default].

    $nano .aws/credentials
    
    [default]
    aws_access_key_id = xyz
    aws_secret_access_key = xyz
    

    If you do not have this file, create it and get your keys or generate new one from aws iam user keys.

    0 讨论(0)
  • 2020-12-02 17:35

    I tried above option and even that did not work, so I created new config object and this below code worked

     AWS.config = new AWS.Config();
     AWS.config.accessKeyId = "AccessKey";
     AWS.config.secretAccessKey = "SecretAccessKey";
    
    0 讨论(0)
  • 2020-12-02 17:41

    I had the same problem until I reversed the two lines:

    var s3 = new AWS.S3();
    AWS.config.loadFromPath('./AwsConfig.json'); 
    

    to this:

    AWS.config.loadFromPath('./AwsConfig.json'); 
    var s3 = new AWS.S3();
    
    0 讨论(0)
提交回复
热议问题