0

I am new NodeJS and trying to alter this sample provided by AWS for reputation list updates however it is specific to CloudFront Global Region only.

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

I have made the changes to the CloudFormation to create regional IPSetID however the function exits on the fact the IPSetID does not exist. I assume this is due to the fact the SDK is looking at global rather than regional i.e eu-west-1 therefore I've set the region in the config but it is still unable to locate the 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();

I've seen a recent question (AWS WAF update ip sets and rules specific to a region from lambda) which shows the URL differences however I do not know where to start to update the 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)"
          ]
        }
Arafat Nalkhande
  • 11,078
  • 9
  • 39
  • 63
Sphinx's
  • 301
  • 1
  • 2
  • 7

1 Answers1

1

You should make sure you have an updated version of the aws-sdk that supports the regional WAF. Change the line var waf = new aws.WAF(); with code similar to the following.

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

I was using versions as follows and got this working. (from package.json node configuration file)

{
  "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"
  }
}

You may need to load the entire zip file containing your code into AWS Lambda.

I used the code contained in https://github.com/itopiacloud/aws-waf-regional-security-automations to help me get this working.

  • I don't get why they wouldn't have one class but if you set a region in the config then it would be regional – Neo Sep 15 '17 at 23:53