zhuzilin's Blog

about

Configure aws-sdk in win10

date: 2018-11-18
tags: aws  powershell  

Install for powershell

First we need to run the powershell as administrator.

With PowerShell 5.0 or higher, the installation can be done with only one line:

Install-Module -Name AWSPowerShell

Set credential

To use aws cli in powershell, we need to run:

Set-ExecutionPolicy RemoteSigned

to allow aws cli to run.

Then we can set the config file with

Set-AWSCredential -AccessKey xxx -SecretKey xxx -StoreAs MyProfileName

The accesskey and secretkey can be found from IAM in aws console.

And then for windows, we need to add a credential file at C:\Users\zhuzilin\.aws\credentials

The content of the file could be:

[default]
aws_access_key_id={YOUR_ACCESS_KEY_ID}
aws_secret_access_key={YOUR_SECRET_ACCESS_KEY}

[profile2]
aws_access_key_id={YOUR_ACCESS_KEY_ID}
aws_secret_access_key={YOUR_SECRET_ACCESS_KEY}

Use aws-sdk in node

Here is an example of using dynamodb

let AWS = require('aws-sdk');
let doc = require('dynamodb-doc');

// Load the AWS API Key from my local, private configuration file.
let credentials = new AWS.SharedIniFileCredentials();
// Set the credential.
AWS.config.credentials = credentials;

AWS.config.update({region: 'us-east-1'});
let awsClient = new AWS.DynamoDB();
let dynamo = new doc.DynamoDB(awsClient);

Here the SharedIniFileCredentials() is using the default credentials.

Reference