Created
October 26, 2021 06:38
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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