guardian / guardian/dotcom-rendering

AWS-SDK : switch to use `AWS.CredentialProviderChain` rather than overriding `AWS_PROFILE` environment variable

Open
#575 2 comments 1 reaction 0 assignees View on GitHub
Team Candidate: WebX
Dominant language
TypeScript
Stars
274
Forks
34
Avg merge
2d 22h
Merged PRs (30d)
121

Description

A while back I followed approach used in [app/aws/aws-metrics.ts](https://github.com/guardian/dotcom-rendering/blob/1299d63efb6cdb27a1f1e2f260f4789508473272/packages/frontend/app/aws/aws-metrics.ts) and [app/aws/aws-parameters.ts](https://github.com/guardian/dotcom-rendering/blob/1299d63efb6cdb27a1f1e2f260f4789508473272/packages/frontend/app/aws/aws-parameters.ts) to connect to S3 from `manage-frontend` (see https://github.com/guardian/manage-frontend/pull/167).

At the time @adamnfish suggested I use `AWS.CredentialProviderChain` rather than overriding the `AWS_PROFILE` environment variable, at the time I couldn't get it working but left rough code commented out ( 😱) - anyway, after a suggestion from @AWare recently (to change the order of items in the provider chain) it now works nicely, without the need to override any environment variables which was a bit nasty.

I would've raised a PR for this repo but know nothing of the codebase, and there might be reasons you don't want to change things.

Here's some example code to create S3 client, which is easily adaptable to your _metrics_ and _parameter_ store use case...
```
const REGION = "eu-west-1";

const PROFILE = "membership";

const CREDENTIAL_PROVIDER = new AWS.CredentialProviderChain([
() => new AWS.SharedIniFileCredentials({ profile: PROFILE }),
...AWS.CredentialProviderChain.defaultProviders
]);

export const S3 = new AWS.S3({
region: REGION,
credentialProvider: CREDENTIAL_PROVIDER
});
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.