Skip to content

Commit 4c097da

Browse files
authored
Configure axios aws interceptor to retrieve credentials from node provider chain at runtime (aws#134)
Configure axios aws interceptor to retrieve credentials from node provider chain at runtime as opposed to on module load. This allows for fresh credentials to be obtained as needed during query runtime. Each environment can have unique credential configuration so I added a link to the aws documentation for configuring credential providers.
1 parent 7d3b10a commit 4c097da

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ permissions and limitations under the License.
7575
properties ([#130](https://github.com/aws/amazon-neptune-for-graphql/pull/130))
7676
* Improved error messaging if query field or selection field types cannot be
7777
determined ([#132](https://github.com/aws/amazon-neptune-for-graphql/pull/132))
78+
* Allow credentials to be refreshed at Apollo runtime by passing the credential
79+
provider to the
80+
interceptor ([#134](https://github.com/aws/amazon-neptune-for-graphql/pull/134))
7881

7982
### Bug Fixes
8083

templates/ApolloServer/neptune.mjs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,29 @@ import { decompressGzipToString } from './util.mjs';
1010
dotenv.config();
1111

1212
const loggingEnabled = process.env.LOGGING_ENABLED === 'true';
13-
const credentialProvider = fromNodeProviderChain();
14-
const credentials = await credentialProvider();
13+
14+
// wrapper that aws4Interceptor can use to obtain credentials
15+
const credentialsProviderWrapper = {
16+
getCredentials: async () => {
17+
// uses the default node provider chain
18+
// see aws documentation for configuration options
19+
// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-credential-providers/#fromnodeproviderchain
20+
try {
21+
const credentialProvider = fromNodeProviderChain();
22+
return await credentialProvider();
23+
} catch (error) {
24+
console.error('Failed to obtain AWS credentials:', error);
25+
throw error;
26+
}
27+
}
28+
};
29+
1530
const interceptor = aws4Interceptor({
1631
options: {
1732
region: process.env.AWS_REGION,
1833
service: process.env.NEPTUNE_TYPE,
1934
},
20-
credentials: credentials
35+
credentials: credentialsProviderWrapper
2136
});
2237
axios.interceptors.request.use(interceptor);
2338
rax.attach();

0 commit comments

Comments
 (0)