简体   繁体   English

我应该如何将 HTTPS 请求发送到 AWS 中的第三方 api

[英]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:您可以使用几个不同的选项:

  1. Amazon Simple Queue Service (SQS)亚马逊简单队列服务 (SQS)
  2. Amazon Simple Notification Service (SNS)亚马逊简单通知服务 (SNS)
  3. AWS SDK for Node.js适用于 Node.js 的 AWS 开发工具包

Option 1 - Amazon Simple Queue Service (SQS)选项 1 - 亚马逊简单队列服务 (SQS)

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 进行传送,还使您能够为失败的请求设置重试策略。

Option 2 - Amazon Simple Notification Service (SNS)选项 2 - 亚马逊简单通知服务 (SNS)

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 进行传递。

Option 3 - AWS SDK for Node.js选项 3 - 适用于 Node.js 的 AWS 开发工具包

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.

相关问题 使用 Google 的 API Explorer 发送 Firebase 云消息时,如何解决“THIRD_PARTY_AUTH_ERROR”背后的问题? - How do I fix the problem behind "THIRD_PARTY_AUTH_ERROR" when using Google's API Explorer to send a Firebase Cloud Messaging message? 使用 golang 服务器对第三方 API 进行速率限制 - Rate limiting for a third party API with a golang server AmazonWebService - 我应该使用 AWS API 网关还是 AWS SDK - AmazonWebService - Should i use AWS API Gateway or AWS SDK 允许第三方应用程序写入您的 aws 存储桶 - allowing a third party application to write to your aws bucket 将 http 移动到 https 后第三方 API 无法正常工作 - After Move http to https of wordpress thrid party API's not working 如何使用 Lambda 访问 AWS API Gateway 请求的 HTTP 标头? - How to access HTTP headers for request to AWS API Gateway using Lambda? AWS API Gateway Lambda 集成(非代理)- 如何发送自定义标头和二进制数据 - AWS API Gateway Lambda Integration (NOT Proxy) - How to Send Custom Headers and Binary Data 如何发送 HTTP 请求以在 firebase 中发送通知? - how to i send HTTP request for sending notification in firebase? 收到错误:AWS API 请求后缺少身份验证令牌 - Getting error: Missing Authentication Token after AWS API request AWS Lambda 上的 .NET Core Web Api 在第一次请求时速度很慢 - .NET Core Web Api on AWS Lambda is slow upon first request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM