简体   繁体   English

如何在AWS Lambda中运行AWS开发工具包Opsworks命令?

[英]How to run AWS SDK Opsworks Commands in AWS Lambda?

I've got a very simple lambda function trying to use the AWS SDK to call opsworks.describeInstances. 我有一个非常简单的lambda函数,试图使用AWS SDK来调用opsworks.describeInstances。 The code executes locally fine, however inside lambda, it times out with no error or feedback. 代码在本地执行正常,但是在lambda内部,它会超时而没有错误或反馈。

var AWS = require('aws-sdk');
var opsworks = new AWS.OpsWorks({
    apiVersion: 'latest',
    region: "us-east-1"
});
exports.handler = function(event, context, callback) {
    var params = {
        LayerId: 'idoflayer'
    };
    opsworks.describeInstances(params, function(err, data) {
        if (err) {
            return callback(err);
        }
        callback(null, data);
    });
};

The lambda policy is: lambda政策是:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "opsworks:CreateDeployment",
                "opsworks:DescribeDeployments",
                "opsworks:DescribeLayers",
                "opsworks:DescribeInstances"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}

I've increased both memory and timeout. 我增加了内存和超时。 The logs only show that function is being called, no output. 日志仅显示正在调用函数,没有输出。 The monitoring of the lambda function shows Invocation errors, but I think this is just due to the timeout. lambda函数的监视显示了Invocation错误,但我认为这只是由于超时。 I'm running this in us-west-2, but I've also tried running it in us-east-1, same result. 我在us-west-2中运行它,但我也尝试在us-east-1中运行它,结果相同。

Any ideas? 有任何想法吗? I'd love to use lambda to monitor and manage OpsWorks. 我很乐意使用lambda来监控和管理OpsWorks。

To solve, I just removed the custom VPC settings, since the function was only trying to access the AWS Opsworks API. 为了解决这个问题,我刚刚删除了自定义VPC设置,因为该功能只是尝试访问AWS Opsworks API。 Also noticed this inside the documentation: 在文档中也注意到了这一点:

When you enable VPC, your Lambda function will lose default internet access. 启用VPC后,您的Lambda函数将失去默认的Internet访问权限。 If you require external internet access for your function, ensure that your security group allows outbound connections and that your VPC has a NAT gateway. 如果您的功能需要外部Internet访问,请确保您的安全组允许出站连接,并确保您的VPC具有NAT网关。

Since Lambda bundles the SDK to be available inside functions and access is determined by IAM policies, it is a little confusing that you still need external access to the internet to use the API. 由于Lambda将SDK捆绑在内部功能中,并且访问权限由IAM策略决定,因此您仍然需要外部访问Internet才能使用API​​,这有点令人困惑。

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

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