CDK构造使用APIGateway(REST)与IoCore进行代理通信。

aws-solutions-constructs.aws-apigateway-iot的Python项目详细描述


aws apigateway物联网模块

---

Stability: Experimental

All classes are under active development and subject to non-backward compatible changes or removal in any future version. These are not subject to the Semantic Versioning model. This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.


Reference Documentation:https://docs.aws.amazon.com/solutions/latest/constructs/
^{tb2}$

概述

这个AWS解决方案构造实现了一个连接到AWS IoT模式的amazonapi网关restapi。在

这个构造在API网关和AWS IoT之间创建了一个可伸缩的HTTPS代理。当希望允许不支持MQTT或MQTT/Websocket协议的遗留设备与AWS IoT平台交互时,这非常有用。在

此实现允许在给定的MQTT主题上发布只写消息,还支持HTTPS设备的影子更新,以允许设备注册表中的内容。它不涉及用于代理消息的Lambda函数,而是依赖于AWS IoT集成的直接API网关,该网关支持JSON消息和二进制消息。在

以下是Typescript中的最小可部署模式定义:

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826fromaws_solutions_constructs.aws_apigateway_iotimportApiGatewayToIotApiGatewayToIot(self,"ApiGatewayToIotPattern",iot_endpoint="a1234567890123-ats")

初始值设定项

^{pr2}$

参数

  • 范围^{}
  • 标识string
  • 道具^{}

构装道具

NameTypeDescription
iotEndpoint^{}The AWS IoT endpoint subdomain to integrate the API Gateway with (e.g a1234567890123-ats).
apiGatewayCreateApiKey?^{}If set to ^{}, an API Key is created and associated to a UsagePlan. User should specify ^{} header while accessing RestApi. Default value set to ^{}
apiGatewayExecutionRole?^{}IAM Role used by the API Gateway to access AWS IoT. If not specified, a default role is created with wildcard ('*') access to all topics and things.
apiGatewayProps?^{}Optional user-provided props to override the default props for the API Gateway.

图案属性

NameTypeDescription
apiGateway^{}Returns an instance of the API Gateway REST API created by the pattern.
apiGatewayRole^{}Returns an instance of the iam.Role created by the construct for API Gateway.
apiGatewayCloudWatchRole^{}Returns an instance of the iam.Role created by the construct for API Gateway for CloudWatch access.
apiGatewayLogGroup^{}Returns an instance of the LogGroup created by the construct for API Gateway access logging to CloudWatch.

默认设置

没有任何重写的构件的现成实现将设置以下默认值:

亚马逊API网关

  • 部署边缘优化的API终结点
  • 使用POST方法创建API资源,以将消息发布到IoT主题
  • 使用POST方法创建API资源,以将消息发布到ThingShadow&NamedShadows
  • 为API网关启用CloudWatch日志记录
  • 为API网关配置IAM角色,以访问所有主题和内容
  • 将所有API方法的默认授权类型设置为IAM
  • 启用X射线跟踪
  • 创建一个使用计划并关联到prod阶段

下面是对部署构造后API网关公开的不同资源和方法的描述。有关如何使用curl轻松测试这些端点的更多信息,请参见Examples部分。在

MethodResourceQuery parameter(s)Return code(s)Description
POST^{}qos^{}By calling this endpoint, you need to pass the topics on which you would like to publish (e.g ^{}).
POST^{}None^{}This route allows to update the shadow document of a thing, given its ^{} using Unnamed (classic) shadow type. The body shall comply with the standard shadow stucture comprising a ^{} node and associated ^{} and ^{} nodes. See the Updating device shadows section for an example.
POST^{}None^{}This route allows to update the named shadow document of a thing, given its ^{} and the ^{} using the Named shadow type. The body shall comply with the standard shadow stucture comprising a ^{} node and associated ^{} and ^{} nodes. See the Updating named shadows section for an example.

建筑

Architecture Diagram

示例

以下示例仅适用于API_KEY身份验证类型,因为IAM授权也需要指定SIGv4令牌,因此在部署堆栈时,请确保构造属性的apiGatewayCreateApiKey属性设置为true,否则以下示例将无法工作。在

发布消息

您可以使用curl使用HTTPS API发布关于不同MQTT主题的消息。下面的示例将在device/foo主题上发布一条消息。在

curl -XPOST https://<stage-id>.execute-api.<region>.amazonaws.com/prod/message/device/foo -H "x-api-key: <api-key>" -H "Content-Type: application/json" -d '{"Hello": "World"}'

Replace the stage-id, region and api-key parameters with your deployment values.

您可以在URL中链接主题名称,API最多接受7个子主题,您可以在这些子主题上发布。例如,下面的示例发布主题为device/foo/bar/abc/xyz的消息。在

curl -XPOST https://<stage-id>.execute-api.<region>.amazonaws.com/prod/message/device/foo/bar/abc/xyz -H "x-api-key: <api-key>" -H "Content-Type: application/json" -d '{"Hello": "World"}'

更新设备阴影

要更新与给定对象关联的卷影文档,可以使用对象名称发出卷影状态请求。请参阅下面的示例,了解如何更新thing shadow。在

curl -XPOST https://<stage-id>.execute-api.<region>.amazonaws.com/prod/shadow/device1 -H "x-api-key: <api-key>" -H "Content-Type: application/json" -d '{"state": {"desired": { "Hello": "World" }}}'

更新命名阴影

要更新与给定对象的命名shadow相关联的shadow文档,可以使用thing name和shadow name发出一个shadow state请求。有关如何更新命名阴影,请参见以下示例。在

curl -XPOST https://<stage-id>.execute-api.<region>.amazonaws.com/prod/shadow/device1/shadow1 -H "x-api-key: <api-key>" -H "Content-Type: application/json" -d '{"state": {"desired": { "Hello": "World" }}}'

发送二进制有效载荷

可以将二进制有效负载发送到代理API,向下发送到AWS IoT服务。在下面的示例中,我们使用application/octet-stream内容类型将与此模块关联的README.md文件的内容(作为二进制数据处理)发送到device/foo主题。在

curl -XPOST https://<stage-id>.execute-api.<region>.amazonaws.com/prod/message/device/foo/bar/baz/qux -H "x-api-key: <api-key>" -H "Content-Type: application/octet-stream" --data-binary @README.md

Execute this command while in the directory of this project. You can then test sending other type of binary files from your file-system.


©版权所有2020亚马逊网站,Inc.或其附属公司。版权所有。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
由于测试失败,java testcontainers maven构建失败   java实现jacobi算法实现laplace方程   java中的多线程:如何在不等待所有线程使用ExecutorService完成任务的情况下终止所有线程的执行?   java Hello World不在Android Studio 3中工作   ubuntu Tomcat7的Java版本不正确   java Javafx内存泄漏   对于手动实现的Spring数据存储库方法,我应该使用Java8默认方法吗?   googleappengine中的java添加过滤查询   html当使用JSOUP库在Java中读取标签时,如何保留标签(如<br>、<ul>、<li>、<p>等)的含义?   编码为什么jasper生成的报告在Java中不显示西里尔语(保加利亚语)?   java有没有办法隐藏当前位置和jdk动作?   java找出编译原型文件的版本   有没有办法在运行时更改java方法的访问修饰符?   语法字符串。。。Java中的参数   java数组元素在添加其他元素时会相互覆盖   eclipse中的java GWT项目   java如何为spring rest模板请求将动态json属性名映射到jackson   java无法在Windows 10上找到特定的JDK   在xml字符串和java字符串之间提取正则表达式子字符串