-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode-18-fetch.ts
33 lines (27 loc) · 925 Bytes
/
node-18-fetch.ts
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
import { LambdaInterface } from "@aws-lambda-powertools/commons";
import { Tracer } from "@aws-lambda-powertools/tracer";
import nodeFetch from "node-fetch";
const tracer = new Tracer();
class Lambda implements LambdaInterface {
// Decorate your handler class method
@tracer.captureMethod()
private async nativeFetch() {
const response = await fetch("https://api.github.com/users/aws-samples");
const json = await response.json();
return json;
}
@tracer.captureMethod()
private async nodeFetch() {
const response = await nodeFetch(
"https://api.github.com/users/aws-samples"
);
const json = await response.json();
return json;
}
public async handler(_event: unknown, _context: unknown): Promise<void> {
await this.nativeFetch();
await this.nodeFetch();
}
}
const handlerClass = new Lambda();
export const handler = handlerClass.handler.bind(handlerClass); //