[英]How should I send HTTPS request to a third-party api in AWS
I am currently implementing proactive reporting in Alexa and left scratching my head about how to properly implement sending the ChangeReport interface to Alexa.我目前正在Alexa 中实施主动报告,并且一直在摸索如何正确实施将 ChangeReport 接口发送到 Alexa。 Currently I am just sending the request through a Lambda function, however this seems like it may be an anti-pattern in AWS Lambda .
目前我只是通过 Lambda 函数发送请求,但这似乎是AWS Lambda 中的反模式。
What I would like to do is have a Lambda function create the proper message payload and then hand the payload off to some AWS service to send the request to the Alexa endpoint.我想要做的是让 Lambda 函数创建适当的消息负载,然后将负载交给某些 AWS 服务以将请求发送到 Alexa 端点。 Ideally This would also have a retry policy in place.
理想情况下,这也会有一个重试策略。
What options do I have to send this request?我有哪些选项可以发送此请求? Am I purely limited to Lambda to do this or can I use another AWS service for this?
我是否只能使用 Lambda 来执行此操作,还是可以为此使用其他 AWS 服务?
Currently I am sending the request through a lambda function, which works but might be an anti-pattern.目前我正在通过 lambda 函数发送请求,该函数有效但可能是一种反模式。 The lambda function is running Node 16 if this is relevant.
如果相关,lambda 函数正在运行节点 16。 I experimented with setting this up in SNS and, unfortunately, SNS requires the endpoint to reply with a confirmation upon subscription.
我尝试在 SNS 中进行设置,不幸的是,SNS 要求端点在订阅时回复确认。
You can send HTTPS requests to a 3rd party API in AWS.您可以将 HTTPS 请求发送到 AWS 中的第三方 API。 There are a few different options you can use:
您可以使用几个不同的选项:
With SQS, you can create a message containing the HTTPS request and add it to a queue.使用 SQS,您可以创建包含 HTTPS 请求的消息并将其添加到队列中。 You can then configure an AWS Lambda function to process messages from the queue and send the HTTPS request.
然后,您可以配置 AWS Lambda 函数来处理来自队列的消息并发送 HTTPS 请求。
This allows you to use Lambda to create the message payload and then hand it off to SQS for delivery, and it also gives you the ability to set up a retry policy for failed requests.这使您可以使用 Lambda 创建消息有效负载,然后将其交给 SQS 进行传送,还使您能够为失败的请求设置重试策略。
With SNS, you can create a message containing the HTTPS request and publish it to a topic.使用 SNS,您可以创建包含 HTTPS 请求的消息并将其发布到主题。 You can then subscribe the third-party API endpoint to the topic, and SNS will automatically deliver the message to the endpoint.
然后,您可以将第三方 API 端点订阅到该主题,SNS 会自动将消息传递到端点。
This allows you to use Lambda to create the message payload and then hand it off to SNS for delivery.这允许您使用 Lambda 创建消息负载,然后将其交给 SNS 进行传递。
AWS SDK provides APIs for making HTTPS requests, and you can use these APIs to send the request directly from your Lambda function. AWS 开发工具包提供用于发出 HTTPS 请求的 API,您可以使用这些 API 直接从您的 Lambda 函数发送请求。
This allows you to use Lambda to create the message payload and send the HTTPS request in a single step.这使您可以使用 Lambda 创建消息负载并一步发送 HTTPS 请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.