-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathindex.mjs
More file actions
52 lines (48 loc) · 1.34 KB
/
index.mjs
File metadata and controls
52 lines (48 loc) · 1.34 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
import {LambdaClient, GetAccountSettingsCommand} from '@aws-sdk/client-lambda';
// Create client outside of handler to reuse
const lambda = new LambdaClient()
// Handler
export const handler = async (event, context) => {
console.log('## ENVIRONMENT VARIABLES: ' + serialize(process.env))
console.log('## CONTEXT: ' + serialize(context))
console.log('## EVENT: ' + serialize(event))
try {
let accountSettings = await lambda.send(new GetAccountSettingsCommand())
return formatResponse(serialize(accountSettings.AccountUsage))
} catch(error) {
return formatError(error)
}
}
var formatResponse = function(body){
var response = {
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"isBase64Encoded": false,
"multiValueHeaders": {
"X-Custom-Header": ["My value", "My other value"],
},
"body": body
}
return response
}
var formatError = function(error){
var response = {
"statusCode": error.statusCode,
"headers": {
"Content-Type": "text/plain",
"x-amzn-ErrorType": error.code
},
"isBase64Encoded": false,
"body": error.code + ": " + error.message
}
return response
}
// Use SDK client
var getAccountSettings = function(){
return lambda.getAccountSettings().promise()
}
var serialize = function(object) {
return JSON.stringify(object, null, 2)
}