'Faking a network outage inside codebuild?

I have an integration test suite that runs in AWS codebuild. The program being tested is supposed to handle network outages by retrying operations, so I want to test that in the suite. Running locally, my test script fakes a network outage by using "route" to route all traffic that should go to the servers I use to loopback instead, activate my program, then after a few seconds remove those entries from the routing table and watch the failed commands succeed on a retry. Works great.

In AWS codebuild, when I run the "sudo route" command it fails with "SIOCADDRT: Operation not permitted". I know I can fake a network outage with iptables, so I tried "sudo iptables -L OUTPUT", and got a similar permission denied error.

Is there some way around this? Or is there another method to fake a network outage that will work in a codebuild container? I only need to block a few IP addresses.

AppSpec.yml:

version: 0.2

phases:
  install:
    runtime-versions:
      python: 3.9
  pre_build:
    commands:
      - pip3 install -r requirements.txt
          $CODEBUILD_SRC_DIR_PhastSchemaPackage/phastschema-1.0.0.tar.gz
          $CODEBUILD_SRC_DIR_PhastDevPackage/phastdev-1.0.0.tar.gz
  build:
    commands:
      - pycodestyle assayuploadertest
      - ( cd assayuploadertest ; pylint --disable=R0904,C0103,C0116,R0201,W0603,C0115,W9012,W9011,C0114,W1514 . )
      - ASSAY_UPLOADER_HOME=$CODEBUILD_SRC_DIR_AssayUploaderZip/src python -m unittest discover -s assayuploadertest


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source