Setting up an SQS-based Lambda function
Previously, we managed to run locally a REST-based AWS Lambda function. Our next component will also be a Lambda function but message-based; more specifically, it will listen to the SQS events we emitted previously.
The Lambda application, by receiving the SQS events, will then persist them in S3. The same components we used previously will also be used for this application.
Let’s see the function handler:
func HandleRequest(ctx context.Context, sqsEvent events.SQSEvent) error { session := s3Session() for _, message := range sqsEvent.Records { var subscribe Subscribe json.Unmarshal([]byte(message.Body), &subscribe) key := fmt.Sprintf("%s.%d", hash(subscribe.Email), time.Now().UnixNano()/int64(time.Millisecond)) ...