简体   繁体   English

在 Lambda 中创建 AWS IOT thingGroup

[英]Create AWS IOT thingGroup in Lambda

I am Trying to create an IOT thing group in a Lambda function.我正在尝试在 Lambda function 中创建一个 IOT 事物组。 When I try run this function it just times out and no other errors appear in the logs.当我尝试运行此 function 时,它只是超时并且日志中没有出现其他错误。 Increasing the execution duration does not help.增加执行持续时间无济于事。

var AWS = require('aws-sdk');
exports.handler = (event, context, callback) => {
    const region = "eu-west-1";
    const iotParams = {"apiVersion": "2019-05-28", "region": region};
    var iot = new AWS.Iot(iotParams);
    var params = {
        thingGroupName: 'test',
        tags: [
            {
                Key: 'name',
                Value: 'test'
            },
            /* more items */
        ],
        thingGroupProperties: {
            attributePayload: {
                attributes: {
                    'name': 'test',
                },
                merge: false
            },
            thingGroupDescription: 'test'
        }
    };
    iot.createThingGroup(params, function(err, data) {
        if (err) {
            callback(err);
        }
        else {
            callback(null, data);
        }
    });
};

Common reason for timeouts when using lambda in a VPC is the fact that lambda in VPC does not have intenet access nor public IP .在 VPC 中使用 lambda 时超时的常见原因是 VPC 中的 lambda没有互联网访问权限,也没有公共 IP From docs :来自文档

Connect your function to private subnets to access private resources.将您的 function 连接到私有子网以访问私有资源。 If your function needs internet access, use NAT.如果您的 function 需要互联网访问,请使用 NAT。 Connecting a function to a public subnet does not give it internet access or a public IP address.将 function 连接到公共子网不会为其提供 Internet 访问权限或公共 IP 地址。

Also the lambda requires special permissions in its execution policy:此外 lambda 在其执行策略中需要特殊权限

ec2:CreateNetworkInterface ec2:创建网络接口

ec2:DescribeNetworkInterfaces ec2:描述网络接口

ec2:DeleteNetworkInterface ec2:删除网络接口

To access AWS services from lambda in VPC, NAT gateway or instance are required.要从 VPC 中的 lambda 访问 AWS 服务,需要NAT 网关或实例。 Alternatively, VPC endpoints can be used for supported services (IoT is not one of them).或者, VPC 端点可用于支持的服务(物联网不是其中之一)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM