SP-API 中 Notifications API 结合 Amazon EventBridge 使用的详细教程

0
0
{"value":"#### **1.基本介绍**\n\n**1.1 Notifications API**\n\nNotifications API 是 SP-API 中的一种接口类型,可以用于创建和管理接收 SP-API 发来的通知消息和消息传递的目的地资源以及相应的订阅。目前支持的订阅的资源类型有 Amazon SQS,以及 Amazon EventBridge。\n相比传统的轮询方式来获取数据,使用 Notifications API 来创建订阅模式,可以在 Amazon 消息产生后直接触发并传递给开发者自己订阅消息的应用,从而有效的地减少轮训请求的次数,提高应用消息的实时性,和代码的维护性。\n\nNotifications API 是一种不需要授权的 Grantless operation API。调用 Grantless API 不需要提供 refresh token\n而是显式的使用 withScope 参数的方式来定义 Scope。SP-API\n中的 Grantless 请求有如下 API:\n\n![1d7f440f7ae881b5745c72271f53e55.jpg](https://dev-media.amazoncloud.cn/b5f61eaf14e8437fa3d142054bff0394_1d7f440f7ae881b5745c72271f53e55.jpg)\n\n目前,Notifications API 支持 EventBridge 的通知类型有:\n\n![54b9554d2ca46c74270f6a1e5c79736.jpg](https://dev-media.amazoncloud.cn/e3161fb500b24cfda6e935feca01497e_54b9554d2ca46c74270f6a1e5c79736.jpg)\n\n支持 SQS 的通知类型可参考 [SP-API 中 Notifications API 结合 Amazon SQS 使用的详细教程](https://aws.amazon.com/cn/blogs/china/detailed-tutorial-on-the-use-of-notifications-api-in-sp-api-with-amazon-sqs/) 中的介绍。\n\n本文将以 LISTINGS_ITEM_STATUS_CHANGE 为例来创建 EventBridge 事件总线的订阅,并将消息发送到订阅 SNS 的邮箱中。\n\n**1.2 Amazon EventBridge**\n\nAmazon EventBridge 是一种无服务器事件总线,可使用从您的应用程序、集成式软件即服务 (SaaS) 应用程序和 AWS 服务生成的事件,更轻松地大规模构建事件驱动型应用程序。EventBridge 提供从事件源(例如 Zendesk, Shopify,或是 Selling Partner API)到目标对象(例如 AWS Lambda 和其他 SaaS 应用程序)的实时数据流。您可以设置路由规则,以确定将数据发送到何处,从而构建在事件发布者和使用者完全解耦的情况下对数据源进行实时响应的应用程序架构。\n\n#### **2.如何配置 Amazon EventBridge 来进行 Notifications API 消息传递**\n\n- 通过调用 Notifications API 创建事件源(Create Destination)\n- 配置 Amazon SNS 话题和订阅,作为接收 EventBridge 的消息终点\n- 配置 Amazon EventBridge 事件源与事件总线,并对事件总线添加规则和目标\n- 通过调用 Notifications API 创建订阅(Create Subscription)\n- 监测到相应事件后,通知自动发送到订阅的 EventBridge 的目的地中\n\n##### **Step1. 通过调用 Notifications API 创建事件源(Create Destination)**\n\n使用 API 的方式来发送 Grantless 请求可参考如下 Python 请求:\n\n```\ngrantless_payload = {'grant_type': 'client_credentials', 'client_id': client_id, 'client_secret': client_secret,\n \"scope\": \"sellingpartnerapi::notifications\"}\n lwa = requests.post(\"https://api.amazon.com/auth/o2/token\", data=grantless_payload)\n```\n\n请求创建 Destination,此处我们以美东一 us-east-1 为例:\n\n```\nPOST https://sellingpartnerapi-na.amazon.com/notifications/v1/destinations\n{\n \"resourceSpecification\":\n {\n \"eventBridge\":\n {\n \"accountId\": \"123456789\",\n \"region\": \"us-east-1\"\n }\n },\n \"name\": \"YourDestinationName\"\n}\n\n```\n\n以 Python 代码的请求为例,向 Notifications API 发送请求并创建 EventBridge 的事件源。\n\n```\nnormal_endpoint = \"https://sellingpartnerapi-na.amazon.com\"\n headers = {'content-type': 'application/json', 'Accept': 'application/json', 'x-amz-access-token': access_token}\n destinationParams = {\n \"resourceSpecification\":\n {\n \"eventBridge\":\n {\n \"accountId\": \"${yourAccountId}\",\n \"region\": \"us-east-1\"\n }\n },\n \"name\": \"yourDestination\"\n }\n\n destinationResponse = requests.post(normal_endpoint + \"/notifications/v1/destinations\",\n data=json.dumps(destinationParams), headers=headers, auth=auth)\n```\n\n返回的结果如下:\n\n```\n{\n \"payload\": {\n \"resource\": {\n \"sqs\": null,\n \"eventBridge\": {\n \"name\": \"aws.partner/sellingpartnerapi.amazon.com/${yourAccountId}/amzn1.sp.solution.id\",\n \"accountId\": \"yourAccountId\",\n \"region\": \"us-east-1\"\n }\n },\n \"destinationId\": \"yourDestinationId\",\n \"name\": \"yourDestinationName\"\n }\n}\n\n```\n\n这里我们记录下 resource:eventBridge:name 和 destinationId 的值,这两个值将在配置 EventBridge 和管理订阅中用到。\n\n##### **Step2. 配置 SNS 话题和订阅,作为 EventBridge 的消息终点**\n\nAmazon SNS 是一种基于 Pub/Sub 模式的托管式消息收发服务,使用 SNS 可以将消息源收到的消息扇出到多个订阅中。本例中我们将使用 Email 订阅的方式作为目的地来接收 SP-API 发往 EventBridge 的消息。这里我们使用 Notifications API 创建 EventBridge 事件源时的 AWS 区域 us-east-1 来进入 [Amazon SNS](https://us-east-1.console.aws.amazon.com/sns/v3/home?region=us-east-1#/topics) 并创建 Topic。\n\nAmazon SNS 是一种基于 Pub/Sub 模式的托管式消息收发服务,使用 SNS 可以将消息源收到的消息扇出到多个订阅中。本例中我们将使用 Email 订阅的方式作为目的地来接收 SP-API 发往 EventBridge 的消息。这里我们使用 Notifications API 创建 EventBridge 事件源时的 AWS 区域 us-east-1 来进入 Amazon SNS 并创建 Topic。\n\n![image.png](https://dev-media.amazoncloud.cn/1930f75e053a4c86ac5fda3bff57313f_image.png)\n\nSNS 的 Topic 类型分为两种,一种是用于对接 FIFO(first-in, first-out) SQS 类型的 Topic,另一种是标准的 Topic。这里我们的 SNS 将用于作为 EventBridge 消息路由的终点,我们选用 Standard 类型的 Topic。并填写好 SNS 的名字。\n\n![image.png](https://dev-media.amazoncloud.cn/11992da016894b0e866783a1a4adb8ba_image.png)\n\n接下来我们来为 SNS 添加订阅的目标用于消息接收。这里我们 Protocol 选择 Email 用作发往邮件的目标订阅。并填写好邮箱地址创建订阅\n\n![image.png](https://dev-media.amazoncloud.cn/ab4ddda2ac9641fa83d733792e199cd1_image.png)\n\n在邮箱中确认好订阅后发往 SNS 的消息即可触达邮箱地址。\n\n![image.png](https://dev-media.amazoncloud.cn/690bfc4f30304f18a339051d7aa08883_image.png)\n\n**Step3. 配置 Amazon EventBridge 事件源与事件总线,并对事件总线添加规则和目标。**\n\n这里我们使用 Notifications API 创建 EventBridge 事件源时的 AWS 区域 us-east-1 来进入 [Amazon EventBridge](http://us-east-1.console.aws.amazon.com/) ,点击\nPartner Event Sources, 可以看到来自 sellingpartnerapi 的事件源。点击 Associate with event bus 来进行关联。\n\n![image.png](https://dev-media.amazoncloud.cn/ec799c9d997f496db306be206f7c8c99_image.png)\n\n关联后,点击 Rules 选项,选择上一步骤中的事件总线,然后点击 Create Rules 来创建新的规则。\n\n![image.png](https://dev-media.amazoncloud.cn/0d282d4c028c4a4e8371c05fdbf0c8ce_image.png)\n\n在 Event source 中选择 AWS events or EventBridge partner events 事件源,此处的事件源即为我们使用 Notifications API 的 Destinations 创建的事件源。\n\n![image.png](https://dev-media.amazoncloud.cn/3adc90ec30e94e668efb5e17b6051fc3_image.png)\n\nEvent Pattern 中可参考如下格式选择 Amazon Selling Partner APIs 的事件\n\n![image.png](https://dev-media.amazoncloud.cn/e341497bfa9f4715882d815a16804641_image.png)\n\n然后选择 Custom patterns, 来定义规则来对 EventBridge 发来的消息进行过滤和路由。\n我们以 LISTINGS_ITEM_STATUS_CHANGE 通知类型为例添加来过滤单一事件类型的规则规则。其他可选的通知类型可参考[通知类型文档](https://developer-docs.amazon.com/sp-api/docs/notifications-api-v1-use-case-guide#notificationtype)中的介绍。\n\n```\n{\n \"source\": [{\n \"prefix\": \"aws.partner/sellingpartnerapi.amazon.com\"\n }],\n\n \"account\": [\"yourAccountId\"],\n \"detail-type\": [\"LISTINGS_ITEM_STATUS_CHANGE\"]\n}\n```\n\n在 Target 中,选择本区域中创建好的 SNS 服务,借助 Amazon SNS 可以通过 SMS,移动推送和电子邮件将消息大规模发送给用户。本例中我们将推送至先前配置好的邮件收件人中。此外 EventBridge 也可将消息推送至其他 EventBridge/Kinesis/SQS/Lambda/Step Function 等目标中,将消息进行分发或处理。\n\n![image.png](https://dev-media.amazoncloud.cn/b52b29a92be3478aaf7bee4e6f4d7344_image.png)\n\n至此,我们完成了 EventBridge 的创建。\n\n##### **Step4. 通过调用 Notifications API 创建订阅(Create Subscription)**\n\n接下来,我们以 LISTINGS_ITEM_STATUS_CHANGE 为例向 SP-API 发送请求来创建 EventBridge 对于通知类型的订阅。\n\n```\ndestinationParams = {\n \"payloadVersion\": \"1.0\",\n \"destinationId\": \"yourDestination\"\n}\n\ncreateSubscriptionResponse = requests.get(normal_endpoint+\"/notifications/v1/subscriptions/LISTINGS_ITEM_STATUS_CHANGE\",\n data=json.dumps(destinationParams),headers=headers, auth=auth)\n```\n\n返回的结果如下:\n\n ```\n \"payload\": {\n \"subscriptionId\": \"yourSubscriptionId\",\n \"payloadVersion\": 1.0,\n \"destinationId\": \"yourDestination\"\n }\n}\n```\n\n至此,我们完成了针对 LISTINGS_ITEM_STATUS_CHANGE 的订阅。\n\n##### **Step5.监测到相应事件后,通知自动发送到订阅 EventBridge 的目的地中**\n\n当我们的 Listing 商品状态发生变化时(例如:Buyable/Discoverable/Delete 等)我们的 SNS 目的地均可以收到通知,通知的对应字段描述如下。\n\n![f1751d88304f54103f2c6c3440dc97f.jpg](https://dev-media.amazoncloud.cn/3210a1969e83473292f2c2e48f7d8e93_f1751d88304f54103f2c6c3440dc97f.jpg)\n\n![image.png](https://dev-media.amazoncloud.cn/2a86969cba584c9aa2b6d261713674a9_image.png)\n\n以上就完成了 Notifications API 结合 Amazon EventBridge 的使用并通过 SNS 发往订阅邮件。\n\n#### **本系列文章**\n\n[如何对接亚马逊电商Selling Partner API](https://aws.amazon.com/cn/blogs/china/how-to-connect-with-amazon-e-commerce-selling-partner-api/)\n\n[创建 SP-API 第三方登录应用并完成 API Call](https://aws.amazon.com/cn/blogs/china/create-sp-api-third-party-login-application-and-complete-api-call/)\n\n[SP-API 中 Notifications API 结合 Amazon SQS 使用的详细教程](https://aws.amazon.com/cn/blogs/china/detailed-tutorial-on-the-use-of-notifications-api-in-sp-api-with-amazon-sqs/)\n\n#### **本篇作者**\n\n![image.png](https://dev-media.amazoncloud.cn/7629bb25f24a49999ceb6058789581b4_image.png)\n\n#### **Aonan Guan**\n亚马逊云科技解决方案架构师,负责基于 AWS 云计算方案架构的咨询和设计,曾任算法工程师和部署平台全栈软件开发工程师。\n\n![image.png](https://dev-media.amazoncloud.cn/7a1a7a73bdf84a7694a2d849fd867524_image.png)\n\n#### **Lei Wang**\n亚马逊 SP-API 中国区负责人。Amazon 解决方案架构师。专注亚马逊电商平台合作伙伴及第三方服务商 ISV 的 SP-API 对接咨询及推广。为中国区开发者提供基于 SP-API 的解决方案。\n\n\n\n\n\n\n","render":"<h4><a id=\"1_0\"></a><strong>1.基本介绍</strong></h4>\n<p><strong>1.1 Notifications API</strong></p>\n<p>Notifications API 是 SP-API 中的一种接口类型,可以用于创建和管理接收 SP-API 发来的通知消息和消息传递的目的地资源以及相应的订阅。目前支持的订阅的资源类型有 Amazon SQS,以及 Amazon EventBridge。<br />\n相比传统的轮询方式来获取数据,使用 Notifications API 来创建订阅模式,可以在 Amazon 消息产生后直接触发并传递给开发者自己订阅消息的应用,从而有效的地减少轮训请求的次数,提高应用消息的实时性,和代码的维护性。</p>\n<p>Notifications API 是一种不需要授权的 Grantless operation API。调用 Grantless API 不需要提供 refresh token<br />\n而是显式的使用 withScope 参数的方式来定义 Scope。SP-API<br />\n中的 Grantless 请求有如下 API:</p>\n<p><img src=\"https://dev-media.amazoncloud.cn/b5f61eaf14e8437fa3d142054bff0394_1d7f440f7ae881b5745c72271f53e55.jpg\" alt=\"1d7f440f7ae881b5745c72271f53e55.jpg\" /></p>\n<p>目前,Notifications API 支持 EventBridge 的通知类型有:</p>\n<p><img src=\"https://dev-media.amazoncloud.cn/e3161fb500b24cfda6e935feca01497e_54b9554d2ca46c74270f6a1e5c79736.jpg\" alt=\"54b9554d2ca46c74270f6a1e5c79736.jpg\" /></p>\n<p>支持 SQS 的通知类型可参考 <a href=\"https://aws.amazon.com/cn/blogs/china/detailed-tutorial-on-the-use-of-notifications-api-in-sp-api-with-amazon-sqs/\" target=\"_blank\">SP-API 中 Notifications API 结合 Amazon SQS 使用的详细教程</a> 中的介绍。</p>\n<p>本文将以 LISTINGS_ITEM_STATUS_CHANGE 为例来创建 EventBridge 事件总线的订阅,并将消息发送到订阅 SNS 的邮箱中。</p>\n<p><strong>1.2 Amazon EventBridge</strong></p>\n<p>Amazon EventBridge 是一种无服务器事件总线,可使用从您的应用程序、集成式软件即服务 (SaaS) 应用程序和 AWS 服务生成的事件,更轻松地大规模构建事件驱动型应用程序。EventBridge 提供从事件源(例如 Zendesk, Shopify,或是 Selling Partner API)到目标对象(例如 AWS Lambda 和其他 SaaS 应用程序)的实时数据流。您可以设置路由规则,以确定将数据发送到何处,从而构建在事件发布者和使用者完全解耦的情况下对数据源进行实时响应的应用程序架构。</p>\n<h4><a id=\"2_Amazon_EventBridge__Notifications_API__25\"></a><strong>2.如何配置 Amazon EventBridge 来进行 Notifications API 消息传递</strong></h4>\n<ul>\n<li>通过调用 Notifications API 创建事件源(Create Destination)</li>\n<li>配置 Amazon SNS 话题和订阅,作为接收 EventBridge 的消息终点</li>\n<li>配置 Amazon EventBridge 事件源与事件总线,并对事件总线添加规则和目标</li>\n<li>通过调用 Notifications API 创建订阅(Create Subscription)</li>\n<li>监测到相应事件后,通知自动发送到订阅的 EventBridge 的目的地中</li>\n</ul>\n<h5><a id=\"Step1__Notifications_API_Create_Destination_33\"></a><strong>Step1. 通过调用 Notifications API 创建事件源(Create Destination)</strong></h5>\n<p>使用 API 的方式来发送 Grantless 请求可参考如下 Python 请求:</p>\n<pre><code class=\"lang-\">grantless_payload = {'grant_type': 'client_credentials', 'client_id': client_id, 'client_secret': client_secret,\n &quot;scope&quot;: &quot;sellingpartnerapi::notifications&quot;}\n lwa = requests.post(&quot;https://api.amazon.com/auth/o2/token&quot;, data=grantless_payload)\n</code></pre>\n<p>请求创建 Destination,此处我们以美东一 us-east-1 为例:</p>\n<pre><code class=\"lang-\">POST https://sellingpartnerapi-na.amazon.com/notifications/v1/destinations\n{\n &quot;resourceSpecification&quot;:\n {\n &quot;eventBridge&quot;:\n {\n &quot;accountId&quot;: &quot;123456789&quot;,\n &quot;region&quot;: &quot;us-east-1&quot;\n }\n },\n &quot;name&quot;: &quot;YourDestinationName&quot;\n}\n\n</code></pre>\n<p>以 Python 代码的请求为例,向 Notifications API 发送请求并创建 EventBridge 的事件源。</p>\n<pre><code class=\"lang-\">normal_endpoint = &quot;https://sellingpartnerapi-na.amazon.com&quot;\n headers = {'content-type': 'application/json', 'Accept': 'application/json', 'x-amz-access-token': access_token}\n destinationParams = {\n &quot;resourceSpecification&quot;:\n {\n &quot;eventBridge&quot;:\n {\n &quot;accountId&quot;: &quot;${yourAccountId}&quot;,\n &quot;region&quot;: &quot;us-east-1&quot;\n }\n },\n &quot;name&quot;: &quot;yourDestination&quot;\n }\n\n destinationResponse = requests.post(normal_endpoint + &quot;/notifications/v1/destinations&quot;,\n data=json.dumps(destinationParams), headers=headers, auth=auth)\n</code></pre>\n<p>返回的结果如下:</p>\n<pre><code class=\"lang-\">{\n &quot;payload&quot;: {\n &quot;resource&quot;: {\n &quot;sqs&quot;: null,\n &quot;eventBridge&quot;: {\n &quot;name&quot;: &quot;aws.partner/sellingpartnerapi.amazon.com/${yourAccountId}/amzn1.sp.solution.id&quot;,\n &quot;accountId&quot;: &quot;yourAccountId&quot;,\n &quot;region&quot;: &quot;us-east-1&quot;\n }\n },\n &quot;destinationId&quot;: &quot;yourDestinationId&quot;,\n &quot;name&quot;: &quot;yourDestinationName&quot;\n }\n}\n\n</code></pre>\n<p>这里我们记录下 resource:eventBridge:name 和 destinationId 的值,这两个值将在配置 EventBridge 和管理订阅中用到。</p>\n<h5><a id=\"Step2__SNS__EventBridge__104\"></a><strong>Step2. 配置 SNS 话题和订阅,作为 EventBridge 的消息终点</strong></h5>\n<p>Amazon SNS 是一种基于 Pub/Sub 模式的托管式消息收发服务,使用 SNS 可以将消息源收到的消息扇出到多个订阅中。本例中我们将使用 Email 订阅的方式作为目的地来接收 SP-API 发往 EventBridge 的消息。这里我们使用 Notifications API 创建 EventBridge 事件源时的 AWS 区域 us-east-1 来进入 <a href=\"https://us-east-1.console.aws.amazon.com/sns/v3/home?region=us-east-1#/topics\" target=\"_blank\">Amazon SNS</a> 并创建 Topic。</p>\n<p>Amazon SNS 是一种基于 Pub/Sub 模式的托管式消息收发服务,使用 SNS 可以将消息源收到的消息扇出到多个订阅中。本例中我们将使用 Email 订阅的方式作为目的地来接收 SP-API 发往 EventBridge 的消息。这里我们使用 Notifications API 创建 EventBridge 事件源时的 AWS 区域 us-east-1 来进入 Amazon SNS 并创建 Topic。</p>\n<p><img src=\"https://dev-media.amazoncloud.cn/1930f75e053a4c86ac5fda3bff57313f_image.png\" alt=\"image.png\" /></p>\n<p>SNS 的 Topic 类型分为两种,一种是用于对接 FIFO(first-in, first-out) SQS 类型的 Topic,另一种是标准的 Topic。这里我们的 SNS 将用于作为 EventBridge 消息路由的终点,我们选用 Standard 类型的 Topic。并填写好 SNS 的名字。</p>\n<p><img src=\"https://dev-media.amazoncloud.cn/11992da016894b0e866783a1a4adb8ba_image.png\" alt=\"image.png\" /></p>\n<p>接下来我们来为 SNS 添加订阅的目标用于消息接收。这里我们 Protocol 选择 Email 用作发往邮件的目标订阅。并填写好邮箱地址创建订阅</p>\n<p><img src=\"https://dev-media.amazoncloud.cn/ab4ddda2ac9641fa83d733792e199cd1_image.png\" alt=\"image.png\" /></p>\n<p>在邮箱中确认好订阅后发往 SNS 的消息即可触达邮箱地址。</p>\n<p><img src=\"https://dev-media.amazoncloud.cn/690bfc4f30304f18a339051d7aa08883_image.png\" alt=\"image.png\" /></p>\n<p><strong>Step3. 配置 Amazon EventBridge 事件源与事件总线,并对事件总线添加规则和目标。</strong></p>\n<p>这里我们使用 Notifications API 创建 EventBridge 事件源时的 AWS 区域 us-east-1 来进入 <a href=\"http://us-east-1.console.aws.amazon.com/\" target=\"_blank\">Amazon EventBridge</a> ,点击<br />\nPartner Event Sources, 可以看到来自 sellingpartnerapi 的事件源。点击 Associate with event bus 来进行关联。</p>\n<p><img src=\"https://dev-media.amazoncloud.cn/ec799c9d997f496db306be206f7c8c99_image.png\" alt=\"image.png\" /></p>\n<p>关联后,点击 Rules 选项,选择上一步骤中的事件总线,然后点击 Create Rules 来创建新的规则。</p>\n<p><img src=\"https://dev-media.amazoncloud.cn/0d282d4c028c4a4e8371c05fdbf0c8ce_image.png\" alt=\"image.png\" /></p>\n<p>在 Event source 中选择 AWS events or EventBridge partner events 事件源,此处的事件源即为我们使用 Notifications API 的 Destinations 创建的事件源。</p>\n<p><img src=\"https://dev-media.amazoncloud.cn/3adc90ec30e94e668efb5e17b6051fc3_image.png\" alt=\"image.png\" /></p>\n<p>Event Pattern 中可参考如下格式选择 Amazon Selling Partner APIs 的事件</p>\n<p><img src=\"https://dev-media.amazoncloud.cn/e341497bfa9f4715882d815a16804641_image.png\" alt=\"image.png\" /></p>\n<p>然后选择 Custom patterns, 来定义规则来对 EventBridge 发来的消息进行过滤和路由。<br />\n我们以 LISTINGS_ITEM_STATUS_CHANGE 通知类型为例添加来过滤单一事件类型的规则规则。其他可选的通知类型可参考<a href=\"https://developer-docs.amazon.com/sp-api/docs/notifications-api-v1-use-case-guide#notificationtype\" target=\"_blank\">通知类型文档</a>中的介绍。</p>\n<pre><code class=\"lang-\">{\n &quot;source&quot;: [{\n &quot;prefix&quot;: &quot;aws.partner/sellingpartnerapi.amazon.com&quot;\n }],\n\n &quot;account&quot;: [&quot;yourAccountId&quot;],\n &quot;detail-type&quot;: [&quot;LISTINGS_ITEM_STATUS_CHANGE&quot;]\n}\n</code></pre>\n<p>在 Target 中,选择本区域中创建好的 SNS 服务,借助 Amazon SNS 可以通过 SMS,移动推送和电子邮件将消息大规模发送给用户。本例中我们将推送至先前配置好的邮件收件人中。此外 EventBridge 也可将消息推送至其他 EventBridge/Kinesis/SQS/Lambda/Step Function 等目标中,将消息进行分发或处理。</p>\n<p><img src=\"https://dev-media.amazoncloud.cn/b52b29a92be3478aaf7bee4e6f4d7344_image.png\" alt=\"image.png\" /></p>\n<p>至此,我们完成了 EventBridge 的创建。</p>\n<h5><a id=\"Step4__Notifications_API_Create_Subscription_163\"></a><strong>Step4. 通过调用 Notifications API 创建订阅(Create Subscription)</strong></h5>\n<p>接下来,我们以 LISTINGS_ITEM_STATUS_CHANGE 为例向 SP-API 发送请求来创建 EventBridge 对于通知类型的订阅。</p>\n<pre><code class=\"lang-\">destinationParams = {\n &quot;payloadVersion&quot;: &quot;1.0&quot;,\n &quot;destinationId&quot;: &quot;yourDestination&quot;\n}\n\ncreateSubscriptionResponse = requests.get(normal_endpoint+&quot;/notifications/v1/subscriptions/LISTINGS_ITEM_STATUS_CHANGE&quot;,\n data=json.dumps(destinationParams),headers=headers, auth=auth)\n</code></pre>\n<p>返回的结果如下:</p>\n<pre><code class=\"lang-\"> &quot;payload&quot;: {\n &quot;subscriptionId&quot;: &quot;yourSubscriptionId&quot;,\n &quot;payloadVersion&quot;: 1.0,\n &quot;destinationId&quot;: &quot;yourDestination&quot;\n }\n}\n</code></pre>\n<p>至此,我们完成了针对 LISTINGS_ITEM_STATUS_CHANGE 的订阅。</p>\n<h5><a id=\"Step5_EventBridge__190\"></a><strong>Step5.监测到相应事件后,通知自动发送到订阅 EventBridge 的目的地中</strong></h5>\n<p>当我们的 Listing 商品状态发生变化时(例如:Buyable/Discoverable/Delete 等)我们的 SNS 目的地均可以收到通知,通知的对应字段描述如下。</p>\n<p><img src=\"https://dev-media.amazoncloud.cn/3210a1969e83473292f2c2e48f7d8e93_f1751d88304f54103f2c6c3440dc97f.jpg\" alt=\"f1751d88304f54103f2c6c3440dc97f.jpg\" /></p>\n<p><img src=\"https://dev-media.amazoncloud.cn/2a86969cba584c9aa2b6d261713674a9_image.png\" alt=\"image.png\" /></p>\n<p>以上就完成了 Notifications API 结合 Amazon EventBridge 的使用并通过 SNS 发往订阅邮件。</p>\n<h4><a id=\"_200\"></a><strong>本系列文章</strong></h4>\n<p><a href=\"https://aws.amazon.com/cn/blogs/china/how-to-connect-with-amazon-e-commerce-selling-partner-api/\" target=\"_blank\">如何对接亚马逊电商Selling Partner API</a></p>\n<p><a href=\"https://aws.amazon.com/cn/blogs/china/create-sp-api-third-party-login-application-and-complete-api-call/\" target=\"_blank\">创建 SP-API 第三方登录应用并完成 API Call</a></p>\n<p><a href=\"https://aws.amazon.com/cn/blogs/china/detailed-tutorial-on-the-use-of-notifications-api-in-sp-api-with-amazon-sqs/\" target=\"_blank\">SP-API 中 Notifications API 结合 Amazon SQS 使用的详细教程</a></p>\n<h4><a id=\"_208\"></a><strong>本篇作者</strong></h4>\n<p><img src=\"https://dev-media.amazoncloud.cn/7629bb25f24a49999ceb6058789581b4_image.png\" alt=\"image.png\" /></p>\n<h4><a id=\"Aonan_Guan_212\"></a><strong>Aonan Guan</strong></h4>\n<p>亚马逊云科技解决方案架构师,负责基于 AWS 云计算方案架构的咨询和设计,曾任算法工程师和部署平台全栈软件开发工程师。</p>\n<p><img src=\"https://dev-media.amazoncloud.cn/7a1a7a73bdf84a7694a2d849fd867524_image.png\" alt=\"image.png\" /></p>\n<h4><a id=\"Lei_Wang_217\"></a><strong>Lei Wang</strong></h4>\n<p>亚马逊 SP-API 中国区负责人。Amazon 解决方案架构师。专注亚马逊电商平台合作伙伴及第三方服务商 ISV 的 SP-API 对接咨询及推广。为中国区开发者提供基于 SP-API 的解决方案。</p>\n"}
目录
亚马逊云科技解决方案 基于行业客户应用场景及技术领域的解决方案
联系亚马逊云科技专家
亚马逊云科技解决方案
基于行业客户应用场景及技术领域的解决方案
联系专家
0
目录
关闭
contact-us