Skip to content

Instantly share code, notes, and snippets.

@amui
Created October 26, 2021 06:38
Show Gist options
  • Select an option

  • Save amui/7cc685895f1780a3d452c6b73c17cb15 to your computer and use it in GitHub Desktop.

Select an option

Save amui/7cc685895f1780a3d452c6b73c17cb15 to your computer and use it in GitHub Desktop.
S3 Client JS v3 w/ Cognito User Pool auth and getObject (V2 style)
// variable 'user' stores the social oauth response through Cognito User Pool
const client = new S3({
region: "<REGION>",
credentials: fromCognitoIdentityPool({
identityPoolId: "<IDENTITY POOL ID>",
logins: {
"cognito-idp.<REGION>.amazonaws.com/<USER POOL ID>": user.signInUserSession.idToken.jwtToken,
},
clientConfig: { region: "<REGION>" },
}),
});
try {
var data = await client.getObject({
Bucket: '<BUCKET NAME>',
Key: '<KEY>',
});
} catch (error) {
console.log("ERROR: ", error);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment