AWS Lambda 请求 SQS 挂起

问题描述 投票:0回答:1

lambda 不在 VPC 上。我正在通过 Node.js v3 SDK 从 AWS Lambda 向 SQS 发出请求。

方法如下-

    public async queueNewArticle(article: CreateArticleDTO): Promise<void> {
        const message = JSON.stringify(article);
        this.logger.debug(`Queueing new article: ${message}`);
        this.logger.debug(`Queue URL: ${this.queueUrl}`);
        const queueUrl = this.configService.getOrThrow<string>('AWS_QUEUE_URL');
        const client = AWSXRay.captureAWSv3Client(new SQSClient());
        try {
            const params = new SendMessageCommand({
                QueueUrl: queueUrl,
                MessageBody: message,
            });

            this.logger.debug(`Sending message: ${JSON.stringify(params, null, 2)}`);

            const response = await client.send(params);
            this.logger.debug(`Message sent. Message ID: ${response.MessageId}`);
            this.logger.debug(JSON.stringify(response, null, 2));
        } catch (err) {
            this.logger.error(err);
            throw err;
        }
    }

记录以及 xray 表明对

client.send
的调用是函数的最后一部分,因为之后没有任何反应,并且跟踪不会记录到 xray。

权限设置适当 - lambda 通过其执行角色在 SQS 上拥有

sqs:SendMessage

amazon-web-services amazon-sqs aws-sdk-js aws-sdk-nodejs
1个回答
0
投票

我的代码库中的其他地方存在竞争条件。事实上 lambda 会在 170 毫秒内执行并且不会超时,这就是赠品。

问题中的代码是有效的。

© www.soinside.com 2019 - 2024. All rights reserved.