-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClimaLambda.ts
More file actions
33 lines (29 loc) · 962 Bytes
/
Copy pathClimaLambda.ts
File metadata and controls
33 lines (29 loc) · 962 Bytes
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 { LambdaClient, InvokeCommand, Lambda } from "@aws-sdk/client-lambda";
import { config } from "dotenv";
config();
const lamdba = new LambdaClient({ region: process.env.AWS_REGION });
async function invokeLambda() {
const functionName = "Clima";
const payload = JSON.stringify({ ciudad: "value" });
const command = new InvokeCommand({
FunctionName: functionName,
Payload: Buffer.from(payload),
InvocationType: "RequestResponse",
});
try {
const response = await lamdba.send(command);
const responsePayload = Buffer.from(response.Payload!).toString();
console.log("Respuest del Lambda:", responsePayload);
if (response.FunctionError) {
console.error(
"Error en la ejecucion del Lambda:",
response.FunctionError,
);
} else {
console.log("Lambda ejecutado correctamente.");
}
} catch (error) {
console.error("Error al invocar el Lambda:", error);
}
}
invokeLambda();