-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathamplify.js
More file actions
67 lines (60 loc) · 1.56 KB
/
amplify.js
File metadata and controls
67 lines (60 loc) · 1.56 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const { SharedIniFileCredentials, SSM } = require('aws-sdk')
const crypto = require('crypto')
const configWithLocal = () => {
if (process.env.REGION && process.env.REGION.match(/fake/)) {
// Config for testing locally with amplify mock
const credentials = new SharedIniFileCredentials({
profile: process.env.AWS_PROFILE || 'sprocs-amplify',
})
return {
credentials,
region: 'us-east-2',
}
} else {
return {}
}
}
// Use dev env when using local mocking
const envWithLocal = () =>
process.env.ENV === 'NONE' ? 'dev' : process.env.ENV
const dynamoDBConfigWithLocal = () => {
if (process.env.REGION && process.env.REGION.match(/fake/)) {
return {
endpoint: 'http://localhost:62224',
region: 'us-fake-1',
accessKeyId: 'fake',
secretAccessKey: 'fake',
}
} else {
return {}
}
}
// get tables in AppSync table name format
const envTableName = (tableName) => {
if (process.env.ENV && process.env.ENV === 'NONE') {
return `${tableName}Table`
} else {
return `${tableName}-${
process.env[`API_${process.env.APP}_GQL_GRAPHQLAPIIDOUTPUT`]
}-${process.env.ENV}`
}
}
const jwtSecretKey = () => {
if (!process.env.JWT_SECRET) {
throw new Error('JWT_SECRET is not set')
}
return crypto.createSecretKey(
Buffer.from(process.env.JWT_SECRET.substring(0, 64), 'hex'),
)
}
const isTestEnv = () => {
return !process.env.ENV || process.env.ENV === 'NONE'
}
module.exports = {
configWithLocal,
envWithLocal,
dynamoDBConfigWithLocal,
envTableName,
jwtSecretKey,
isTestEnv,
}