0

我是新的 NodeJS,并试图更改 AWS 提供的此示例以更新信誉列表,但它仅特定于 CloudFront 全球区域。

https://github.com/awslabs/aws-waf-sample/tree/master/waf-reputation-lists

我已经对 CloudFormation 进行了更改以创建区域 IPSetID,但是该函数在 IPSetID 不存在的情况下退出。我认为这是因为 SDK 正在查看全局而不是区域,即 eu-west-1,因此我在配置中设置了区域,但它仍然无法找到 IPSet。

var aws = require('aws-sdk');

// configure API retries
aws.config.update({
    region:'eu-west-1',
    maxRetries: 3,
    retryDelayOptions: {
        base: 1000
    }
});
var waf = new aws.WAF();

我看到了一个最近的问题(AWS WAF 更新 ip sets and rules specific to a region from lambda),它显示了 URL 的差异,但是我不知道从哪里开始更新 URL?

Error getting IP sets { [WAFNonexistentItemException: The referenced item does not exist.]
          message: 'The referenced item does not exist.',
          code: 'WAFNonexistentItemException',
          statusCode: 400,
          retryable: false,
          retryDelay: 162.11187234148383 }

    Error getting ranges and/or IP sets { [WAFNonexistentItemException: The referenced item does not exist.]
          message: 'The referenced item does not exist.',
          code: 'WAFNonexistentItemException',
          statusCode: 400,
          retryable: false,
          retryDelay: 162.11187234148383 }


        {
          "errorMessage": "The referenced item does not exist.",
          "errorType": "WAFNonexistentItemException",
          "stackTrace": [
            "Request.extractError (/var/task/node_modules/aws-sdk/lib/protocol/json.js:48:27)",
            "Request.callListeners (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:105:20)",
            "Request.emit (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:77:10)",
            "Request.emit (/var/task/node_modules/aws-sdk/lib/request.js:682:14)",
            "Request.transition (/var/task/node_modules/aws-sdk/lib/request.js:22:10)",
            "AcceptorStateMachine.runTo (/var/task/node_modules/aws-sdk/lib/state_machine.js:14:12)",
            "/var/task/node_modules/aws-sdk/lib/state_machine.js:26:10",
            "Request.<anonymous> (/var/task/node_modules/aws-sdk/lib/request.js:38:9)",
            "Request.<anonymous> (/var/task/node_modules/aws-sdk/lib/request.js:684:12)",
            "Request.callListeners (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:115:18)"
          ]
        }
4

1 回答 1

1

您应该确保拥有支持区域 WAF 的更新版本的 aws-sdk。更改行 var waf = new aws.WAF(); 使用类似于以下的代码。

var readline = require('readline');
var aws = require('aws-sdk');
var https = require('https');
var async = require('async');

    // configure API retries
    aws.config.update({
        region:'eu-west-1',
        maxRetries: 3,
        retryDelayOptions: {
            base: 1000
        }
    });
    var waf = new aws.WAFRegional();
    var cloudwatch = new aws.CloudWatch();
    var cloudformation = new aws.CloudFormation();

我正在使用以下版本并使其正常工作。(来自 package.json 节点配置文件)

{
  "name": "reputation-lists-parser",
  "version": "1.0.0",
  "description": "",
  "main": "reputation-lists-parser.js",
  "dependencies": {
    "aws-sdk": "^2.76.0",
    "async": "^2.4.1",
    "xml2js": "^0.4.17"
  }
}

您可能需要将包含您的代码的整个 zip 文件加载到 AWS Lambda 中。

我使用了https://github.com/itopiacloud/aws-waf-regional-security-automations中包含的代码来帮助我完成这项工作。

于 2017-06-23T09:41:47.047 回答