Node.js aws Lambda SQS函数未触发

时间:2020-06-24 21:30:36

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

我有一个lambda函数,尝试从aws-sdk调用SQS函数,但它们不会触发。对于我的功能,我有两个权限策略AmazonSQSFullAccess和AWSLambdaFullAccess。可以通过SQS消息调用该函数,但是当我调用sqs.listQueues,sks.createQueue或sqs.sendMessage时,它什么也没做。

const AWS = require('aws-sdk')
const sqs = new AWS.SQS();

exports.handler = async (event) => {
  console.log(event);
  
  sqs.listQueues({}, function(err, data) {
    if (err) {
      console.log("Error", err);
    } else {
      console.log("Success", data.QueueUrls);
    }
  });
  
  var params = {
    QueueName: 'Test Queue',
    Attributes: {
      'DelaySeconds': '60',
      'MessageRetentionPeriod': '86400'
    }
  };

  sqs.createQueue(params, function(err, data) {
    if (err) {
      console.log("Error", err);
    } else {
      console.log("Success", data.QueueUrl);
    }
  });
};

以下是日志输出:

START RequestId: 0e345c02-b5f2-4816-8e58-c9a8cfbc4069 Version: $LATEST<br/>
2020-06-24T21:26:40.697Z    0e345c02-b5f2-4816-8e58-c9a8cfbc4069    INFO    { key1: 'value1', key2: 'value2', key3: 'value3' }<br/>
END RequestId: 0e345c02-b5f2-4816-8e58-c9a8cfbc4069<br/>
REPORT RequestId: 0e345c02-b5f2-4816-8e58-c9a8cfbc4069  Duration: 521.92 ms Billed Duration: 600 ms Memory Size: 128 MB Max Memory Used: 83 MB  Init Duration: 370.65 ms

我已经创建了两个未记录的队列,并且没有出现新的“测试队列”。 这是权限问题还是配置问题,还是其他所有问题?

1 个答案:

答案 0 :(得分:1)

以下代码有效(已测试上市和创建)。在SQS页面上也检查了创建的一个。我将<Biml xmlns="http://schemas.varigence.com/biml.xsd"> <!-- 221 --> <!-- IF EXISTS (SELECT * from sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[autoadmin_backup_configuration_summary]') AND type IN (N'V')) DROP VIEW [dbo].[autoadmin_backup_configuration_summary] GO CREATE VIEW [dbo].[autoadmin_backup_configuration_summary] AS SELECT ManagedBackupVersion, IsAlwaysOn, IsDropped, IsEnabled, RetentionPeriod, EncryptionAlgorithm, SchedulingOption, DayOfWeek, COUNT(*) AS DatabaseCount FROM autoadmin_backup_configurations GROUP BY ManagedBackupVersion, IsAlwaysOn, IsDropped, IsEnabled, RetentionPeriod, EncryptionAlgorithm, SchedulingOption, DayOfWeek GO --> </Biml> await一起使用。

还要注意队列名称,请检查restrictions

队列名称最多可以包含80个字符。可以接受以下字符:字母数字字符,连字符(-)和下划线(_)。

promise