【问题标题】:Create AWS IOT thingGroup in Lambda在 Lambda 中创建 AWS IOT thingGroup
【发布时间】:2020-05-21 19:12:38
【问题描述】:

我正在尝试在 Lambda 函数中创建一个 IOT 事物组。当我尝试运行此功能时,它只是超时并且日志中没有出现其他错误。增加执行时间并没有帮助。

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);
        }
    });
};

【问题讨论】:

  • VPC 中有 lambda 吗?
  • @Marcin 是的,它在 VPC 中
  • 我提供了一些在 vpc 中使用 lambda 时值得检查的信息。

标签: node.js amazon-web-services aws-lambda aws-iot


【解决方案1】:

在 VPC 中使用 lambda 时超时的常见原因是 VPC 中的 lambda 没有互联网访问权限,也没有公共 IP。来自docs

将您的函数连接到私有子网以访问私有资源。如果您的函数需要访问 Internet,请使用 NAT。将函数连接到公共子网不会为其提供 Internet 访问权限或公共 IP 地址。

另外,lambda 在其执行策略中需要特殊的permissions

ec2:CreateNetworkInterface

ec2:DescribeNetworkInterfaces

ec2:删除网络接口

要从 VPC 中的 lambda 访问 AWS 服务,需要 NAT 网关 或实例。或者,VPC endpoints 可用于支持的服务(物联网不是其中之一)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-28
    • 2021-12-30
    • 2017-02-22
    • 2019-05-03
    • 2018-03-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多