Search code examples
pythonamazon-web-servicesamazon-waf

AWS CDK use csv file with IPs in IPSET


I want to add to my IPSet 20+ IP addresses from csv file and i want to configure it from CDK. My csv file looks like that:

"1.12.3.155/32"
"1.12.3.0/18"
"2.22.3.0/22"

And my code for IPset in cdk:

with open('./test/test-ips.csv', 'r') as fin:
    ips = fin.read().splitlines()

 ipset = wafv2.CfnIPSet(
        scope_=self,
        name='name',
        id='ipset',
        scope='REGIONAL',
        description='Block ips',
        addresses= ips,
        ip_address_version="IPV4",

Now with 1 IP in the CSV file, everything works, but when i'm adding multiple IPs, i'm getting this error when i run "cdk deploy".

Resource handler returned message: "Error reason: The parameter contains formatting that is not valid., field: IP_ADDRESS, parameter: "1.2.3.4/18" (Service: Wafv2, Status Code: 400, Request ID: 111aa7-81f1-411e-a222-312330957db, Extended Request ID: null)" (RequestToken: 111111-2323-4343-06ff-69e7918ce2e4 , HandlerErrorCode: InvalidRequest)


Solution

  • SOLVED: I removed the quotes from the IPs and everything works.