-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.mjs
41 lines (36 loc) · 1.07 KB
/
index.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Amplify, API, Auth } from "aws-amplify";
import dotenv from "dotenv";
dotenv.config();
// see also https://docs.amplify.aws/lib/restapi/getting-started/q/platform/js
Amplify.configure({
// OPTIONAL - if your API requires authentication
Auth: {
// REQUIRED - Amazon Cognito Identity Pool ID
identityPoolId: process.env.IDENTITY_POOL_ID,
// REQUIRED - Amazon Cognito Region
region: "ap-northeast-1",
// OPTIONAL - Amazon Cognito User Pool ID
userPoolId: process.env.USER_POOL_ID,
// OPTIONAL - Amazon Cognito Web Client ID (26-char alphanumeric string)
userPoolWebClientId: process.env.APP_CLIENT_ID,
},
API: {
endpoints: [
{
name: "MyApi",
endpoint: process.env.ORION_ENDPOINT,
},
],
},
});
const user = await Auth.signIn(process.env.USERNAME, process.env.PASSWORD);
const token = user.signInUserSession.idToken.jwtToken;
console.log(`idToken: ${token}`);
const myInit = {
headers: {
Authorization: token,
},
};
API.get("MyApi", "/version", myInit).then((response) => {
console.log(response);
});