Skip to content

Commit

Permalink
Upgraded to JavaScript aws-sdk-v3
Browse files Browse the repository at this point in the history
  • Loading branch information
victorskl committed Aug 13, 2024
1 parent 4baa5b1 commit 1887b0d
Show file tree
Hide file tree
Showing 3 changed files with 734 additions and 36 deletions.
29 changes: 15 additions & 14 deletions docs/examples/portal_api_sig4.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
// -*- coding: utf-8 -*-
/**
Usage:
yarn add aws4-axios axios aws-sdk
export AWS_PROFILE=prodops
node portal_api_sig4.js
yarn add aws4-axios axios @aws-sdk/credential-providers
export AWS_PROFILE=prod
node portal_api_sig4.js
**/
import axios from 'axios';
import AWS from 'aws-sdk';
import {fromIni} from '@aws-sdk/credential-providers';
import {aws4Interceptor} from 'aws4-axios';

// https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-credentials-node.html
const credentials = new AWS.SharedIniFileCredentials();
// https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html
const credentialsProvider = fromIni();
// console.log(await credentialsProvider())

const interceptor = aws4Interceptor(
{
region: 'ap-southeast-2',
service: 'execute-api',
},
credentials
);
const interceptor = aws4Interceptor({
options: {
region: 'ap-southeast-2',
service: 'execute-api',
},
credentials: await credentialsProvider(),
});

axios.interceptors.request.use(interceptor);

axios.get('https://api.portal.prod.umccr.org/iam/lims').then((res) => {
console.log(res.data)
console.log(res.data)
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"serverless": "serverless"
},
"dependencies": {
"aws-sdk": "^2.1671.0",
"@aws-sdk/credential-providers": "^3.629.0",
"aws4-axios": "^3.3.7",
"axios": "^1.7.3"
},
Expand Down
Loading

0 comments on commit 1887b0d

Please sign in to comment.