-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.mjs
More file actions
45 lines (36 loc) · 1.07 KB
/
index.mjs
File metadata and controls
45 lines (36 loc) · 1.07 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
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const axios = require('axios');
const { sendDistributionMetric } = require('datadog-lambda-js');
export const handler = async(event, context, callback) => {
console.log(event.body);
var urltocheck = event["queryStringParameters"]['urltocheck']
var fullURL = 'https://api.websitecarbon.com/site?url='+urltocheck;
var config = {
method: 'get',
maxBodyLength: Infinity,
url: fullURL,
headers: { }
};
console.log(fullURL)
sendDistributionMetric(
'lambda.testing_custom_metric', // Metric name
12.45, // Metric value
'product:aws-node-test' // First tag
);
return axios(config)
.then(function (response) {
var response = {
"statusCode": 200,
"headers": {
"my_header": "my_value"
},
"body": JSON.stringify(response.data.statistics),
"isBase64Encoded": false
};
return response;
})
.catch(function (error) {
console.log(error);
});
};