Configuring region in Node.js AWS SDK

前端 未结 14 1522
失恋的感觉
失恋的感觉 2020-12-05 03:30

Can someone explain how to fix a missing config error with Node.js? I\'ve followed all the examples from the aws doc page but I still get this error no matter what.

相关标签:
14条回答
  • 2020-12-05 04:26

    I know I am EXTREMELY late to the party, but I have an additional solution which worked for me.

    It might be worth passing credentials to each resource directly.

    let lambda = AWS.Lambda({region: "us-east-1"});
    let credentials = new AWS.SharedIniFileCredentials({
        profile: PROFILE_NAME,   
    });
    
    lambda.config.credentials = credentials;
    
    0 讨论(0)
  • 2020-12-05 04:30

    Same error for me:

    After doing a lot of trials I have settled on the below:

    OPTION 1

    1. set the AWS_REGION environment variable in local system only, to us-east-1 (example)

    For Linux:

    export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
    export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
    export AWS_DEFAULT_REGION=us-east-1

    For Windows
    see: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html

    1. now, no need to set any lambda variables for region
    2. also, no need to use in code, for example:

      • AWS.config.update(...), this is not required
      • AWS.S3(), etc., these will work without any problems. In place of S3, there can be any aws service

    In a rare case if somewhere some defaults are assumed in code and you are forced to send region, then use {'region': process.env.AWS_REGION})


    OPTION 2

    Instead of environment variables, another way is AWS CONFIG file:

    On Linux you can create below files:

    ~/.aws/credentials

    [default]
    aws_access_key_id=AKIAIOSFODNN7EXAMPLE
    aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
    

    ~/.aws/config

    [default]
    region=us-west-2
    output=json
    

    See https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html

    0 讨论(0)
提交回复
热议问题