-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
54 lines (49 loc) · 1.38 KB
/
index.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* eslint-disable @typescript-eslint/require-await */
import { SQSClient, SendMessageCommand } from "@aws-sdk/client-sqs";
const sqsClient = new SQSClient({ region: "ap-southeast-2" });
import type {
APIGatewayProxyEventV2,
APIGatewayProxyResultV2,
} from "aws-lambda";
const REMOTION_QUEUE_URL = process.env.REMOTION_QUEUE_URL;
export async function main(
event: APIGatewayProxyEventV2
): Promise<APIGatewayProxyResultV2> {
if (event.body) {
const params = {
DelaySeconds: 10,
MessageAttributes: {},
MessageBody: event.body,
QueueUrl: REMOTION_QUEUE_URL,
};
try {
const data = await sqsClient.send(new SendMessageCommand(params));
if (data) {
console.log("Success, message sent. MessageID:", data.MessageId);
const message =
"Message Send to SQS- Here is MessageId: " + data.MessageId;
return {
statusCode: 200,
body: JSON.stringify({
message,
}),
};
} else {
return {
statusCode: 500,
body: JSON.stringify({ message: "Some error occured !!" }),
};
}
} catch (err) {
console.log("Error", err);
return {
statusCode: 500,
body: JSON.stringify({ message: err.message }),
};
}
}
return {
statusCode: 400,
body: JSON.stringify({ message: "Invalid request" }),
};
}