无法将消息从Lambda发送到SQS

时间:2020-07-13 15:28:48

标签: amazon-web-services amazon-s3 amazon-sqs amazon-sns

我只需要将包含特定属性(元数据)的特定文件从我的s3存储桶发送到SQS。我不确定什么是最好的方法。由于SQS没有过滤器选项,也没有SNS。

编辑:我按照指示进行操作,并将lambda与s3连接,以在sqs中发送消息,但是仍然存在问题。 SQS说“正在发送消息”,而不是收到消息。轮询消息时看不到消息。

public async Task<SendMessageResponse> FunctionHandler(S3Event evnt, ILambdaContext context)
    {
        Task<SendMessageResponse> sendMessageResponse;
        var s3Event = evnt.Records?[0].S3;
        try
        {
            var meta = "x-amz-meta-ml-score";
            SendMessageRequest sendMessageRequest = new SendMessageRequest();
            var response = await this.S3Client.GetObjectMetadataAsync(s3Event.Bucket.Name, s3Event.Object.Key);
            
            

            foreach (string metadata in response.Metadata.Keys)
            {
                if (metadata == meta)
                {
                    sendMessageRequest.QueueUrl = myQueueUrl;
                    sendMessageRequest.MessageBody = evnt.ToString();
                    sendMessageRequest.MessageBody = s3Event.ToString();
                    //sendMessageResponse = await SQSCleint.SendMessageAsync(sendMessageRequest);
                }
            }
            

            return await this.SQSCleint.SendMessageAsync(sendMessageRequest);
        }
        catch(Exception e)
        {
            context.Logger.LogLine($"Error getting object {s3Event.Object.Key} from bucket {s3Event.Bucket.Name}. Make sure they exist and your bucket is in the same region as this function.");
            context.Logger.LogLine(e.Message);
            context.Logger.LogLine(e.StackTrace);
            throw;
        }
    }

0 个答案:

没有答案