AWS Lambda function for setting up a traffic mirror session
Go to file
2022-03-16 19:45:31 +03:00
lambda_function.py Initial commit 2022-03-16 19:45:31 +03:00
README.md Initial commit 2022-03-16 19:45:31 +03:00
requirements.txt Initial commit 2022-03-16 19:45:31 +03:00

AWS Lambda function for setting up a traffic mirror session

The function is intended to be triggered by CloudWatch events.

Example event pattern:

{
  "detail-type": [
    "EC2 Instance State-change Notification"
  ],
  "detail": {
    "state": [
      "running"
    ]
  },
  "source": [
    "aws.ec2"
  ]
}

Required environment variables

  • MIRROR_TARGET_ID
  • MIRROR_FILTER_ID

Optional environment variables

  • MIRROR_SKIP_TAGS (should be used to exclude some instances from mirroring, example: "instance_key_with_exact_value=value,key_with_empty_value=,key_present")

Test

import lambda_function

sample_event = {
    "source": [
        "aws.ec2"
    ],
    "detail-type": [
        "EC2 Instance State-change Notification"
    ],
    "detail": {
        "state": [
            "running"
        ],
        "instance-id": "i-060332d6730812468"
    }
}

lambda_handler(sample_event, None)

Troubleshooting

Set LAMBDA_LOG_LEVEL env variable to required log level, eg. INFO