File tree Expand file tree Collapse file tree 4 files changed +24
-52
lines changed
aws-node-typescript-sqs-standard Expand file tree Collapse file tree 4 files changed +24
-52
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ authorAvatar: 'https://avatars3.githubusercontent.com/u/28927258?s=460&v=4'
1515
1616This example demonstrates how to setup a SQS Standard and send messages through the message body and attributes.
1717
18- The queue was created by using [ queue construct from the Lift plugin] ( https://github.com/getlift/lift/blob/master/docs/queue.md ) , which works perfectly!
18+ The queue was created by using the [ queue construct from the Lift plugin] ( https://github.com/getlift/lift/blob/master/docs/queue.md ) .
1919
2020## Use Cases
2121
Original file line number Diff line number Diff line change 11import { SQSEvent , SQSHandler , SQSMessageAttributes } from "aws-lambda" ;
22
33export const handler : SQSHandler = async ( event : SQSEvent ) : Promise < void > => {
4- try {
5- for ( const record of event . Records ) {
6- const messageAttributes : SQSMessageAttributes = record . messageAttributes ;
7- console . log (
8- "Message Attributtes --> " ,
9- messageAttributes . AttributeNameHere . stringValue
10- ) ;
11- console . log ( "Message Body --> " , record . body ) ;
12- // Do something
13- }
14- } catch ( error ) {
15- console . log ( error ) ;
4+ for ( const record of event . Records ) {
5+ const messageAttributes : SQSMessageAttributes = record . messageAttributes ;
6+ console . log (
7+ "Message Attributtes --> " ,
8+ messageAttributes . AttributeNameHere . stringValue
9+ ) ;
10+ console . log ( "Message Body --> " , record . body ) ;
11+ // Do something
1612 }
1713} ;
Original file line number Diff line number Diff line change 1- import {
2- APIGatewayProxyHandler ,
3- APIGatewayProxyEvent ,
4- APIGatewayProxyResult ,
5- } from "aws-lambda" ;
1+ import { APIGatewayProxyHandler , APIGatewayProxyResult } from "aws-lambda" ;
62import { SQS } from "aws-sdk" ;
73
84const sqs = new SQS ( ) ;
95
10- export const handler : APIGatewayProxyHandler = async (
11- event : APIGatewayProxyEvent
12- ) : Promise < APIGatewayProxyResult > => {
13- let statusCode : number = 200 ;
14- let message : string ;
6+ export const handler : APIGatewayProxyHandler =
7+ async ( ) : Promise < APIGatewayProxyResult > => {
8+ let statusCode : number = 200 ;
9+ const message = "Hello world" ;
1510
16- if ( ! event . body ) {
17- return {
18- statusCode : 400 ,
19- body : JSON . stringify ( {
20- message : "No body was found" ,
21- } ) ,
22- } ;
23- }
24-
25- const queueUrl : string = process . env . QUEUE_URL ;
26- console . log ( "event.body" ) , event . body ;
27- try {
11+ const queueUrl : string = process . env . QUEUE_URL ;
2812 await sqs
2913 . sendMessage ( {
3014 QueueUrl : queueUrl ,
31- MessageBody : event . body ,
15+ MessageBody : message ,
3216 MessageAttributes : {
3317 AttributeNameHere : {
3418 StringValue : "Attribute Value Here" ,
@@ -38,17 +22,10 @@ export const handler: APIGatewayProxyHandler = async (
3822 } )
3923 . promise ( ) ;
4024
41- message = "Message placed in the Queue!" ;
42- } catch ( error ) {
43- console . log ( error ) ;
44- message = error ;
45- statusCode = 500 ;
46- }
47-
48- return {
49- statusCode,
50- body : JSON . stringify ( {
51- message,
52- } ) ,
25+ return {
26+ statusCode,
27+ body : JSON . stringify ( {
28+ message,
29+ } ) ,
30+ } ;
5331 } ;
54- } ;
Original file line number Diff line number Diff line change @@ -9,10 +9,9 @@ plugins:
99provider :
1010 name : aws
1111 runtime : nodejs14.x
12- logRetentionInDays : 30
1312
1413constructs :
15- mySimpleQueue :
14+ queue :
1615 type : queue
1716 worker :
1817 handler : handlers/receiver.handler
@@ -21,7 +20,7 @@ functions:
2120 sender :
2221 handler : handlers/sender.handler
2322 environment :
24- QUEUE_URL : ${construct:mySimpleQueue .queueUrl}
23+ QUEUE_URL : ${construct:queue .queueUrl}
2524 events :
2625 - httpApi :
2726 method : post
You can’t perform that action at this time.
0 commit comments