Skip to content

EventBridge events for IPAM Pool CIDR Allocation

0

I'm leading a cloud migration from on-prem and my network engineer is insisting that all the AWS VPC cidr blocks get tracked in his on-prem IPAM. I'm using AWS IPAM with a pool per region to automatically allocate CIDR blocks to VPCs when they are created via LZA. I'm trying to find a way to automate backfilling the on-prem IPAM - my plan was to use a lambda attached to EventBridge and just make api calls to it, but I can't find anything about events in EventBridge for this purpose. I created a custom rule that targeted a SQS queue for testing and nothing came up with the following pattern (suggested by Claude as I couldn't find anything better).

{
  "source": ["aws.cloudtrail"],
  "detail-type": ["AWS API Call via CloudTrail"],
  "detail": {
    "eventSource": ["ec2.amazonaws.com"],
    "eventName": ["AllocateIpamPoolCidr", "ReleaseIpamPoolAllocation", "ProvisionIpamPoolCidr", "DeprovisionIpamPoolCidr", "ModifyIpamResourceCidr"]
  }
}

What's the best way to trigger something based on IPAM CIDR allocations?

2 Answers
1
Accepted Answer

There are a couple of important points to consider here that may help you solve this more effectively:

1. Fix the source Field in Your EventBridge Rule

Your event pattern has "source": ["aws.cloudtrail"], but for CloudTrail-based API call events in EventBridge, the source field should match the service that made the API call, not CloudTrail itself. Since IPAM is part of the EC2 service, update your pattern to:

{
  "source": ["aws.ec2"],
  "detail-type": ["AWS API Call via CloudTrail"],
  "detail": {
    "eventSource": ["ec2.amazonaws.com"],
    "eventName": ["AllocateIpamPoolCidr", "ReleaseIpamPoolAllocation"]
  }
}

2. LZA May Not Call IPAM APIs Directly

When LZA creates a VPC with an IPAM pool association, the actual CIDR allocation may happen implicitly as part of the CreateVpc or AssociateVpcCidrBlock API call, rather than as a separate AllocateIpamPoolCidr call.

Check your CloudTrail logs (CloudTrail Console > Event History, filter by event source ec2.amazonaws.com) for the exact eventName that appears when a VPC is created through LZA. You may find that you need to match on:

"eventName": ["CreateVpc", "AssociateVpcCidrBlock"]

The allocated CIDR information will be available in detail.responseElements, which your Lambda can parse and forward to the on-prem IPAM.

3. Alternative: Polling-Based Approach

If EventBridge-based real-time capture proves unreliable, consider a polling architecture instead:

  • Use EventBridge Scheduler (e.g., every 5 minutes) to invoke a Lambda function.
  • In the Lambda, call the GetIpamPoolAllocations API for each IPAM pool to retrieve current allocations.
  • Track already-synced allocations in a DynamoDB table and only push deltas to the on-prem IPAM.

This approach is more resilient since you won't miss allocations due to event delivery issues.

4. Alternative: AWS Config Change Tracking

AWS Config tracks VPC CIDR changes as configuration items. You can set up:

  • AWS Config to monitor AWS::EC2::VPC resource changes.
  • A custom Config rule with a Lambda function that triggers whenever a VPC's CIDR configuration changes.

The configuration item will include the CIDR block details, which you can then push to your on-prem IPAM. This approach is more reliable because it operates on the actual resource state rather than depending on specific API call names.

AWS

answered a month ago

EXPERT

reviewed a month ago

  • Thanks, I haven't really dealt with CloudTrail events before now. The lambda is set up as both an event consumer and a periodic reconciliation job, kind of a "belt-and-suspenders" approach to try and be as real-time as possible while still allowing for things that happen unexpectedly. The LZA does seem to use the IPAM API call - I found a CloudTrail event in the account event history before I opened this post to see if it my rule didn't trigger or if there wasn't an event. Everything is supposed to be IPAM and IaC (accounts and VPCs all go through the LZA) - and I'm not giving anyone permissions to do it any other way to make sure they follow the golden path.

    Thanks again.

0

For IPAM Pool CIDR allocations, EventBridge events are delivered through AWS CloudTrail. Your event pattern structure is correct, but you may need to adjust the specific API call names you're targeting.

The proper format for matching EC2 service events (which includes IPAM) delivered via CloudTrail should have:

  • source: "aws.ec2"
  • detail-type: "AWS API Call via CloudTrail"
  • detail.eventSource: "ec2.amazonaws.com"
  • detail.eventName: array of specific API calls to match

For IPAM CIDR allocations, the key API calls to monitor are likely related to IPAM pool operations and VPC CIDR associations. You'll want to capture events like when a VPC gets a CIDR from an IPAM pool.

A few troubleshooting steps:

  1. Verify CloudTrail is enabled and logging management events in your region - EventBridge receives these events from CloudTrail on a best effort basis.

  2. Test with a broader pattern first to see what events are actually being generated. Try matching all EC2 API calls temporarily to identify the exact event names being emitted during your IPAM operations.

  3. The specific IPAM API call names in your pattern may not match what's actually being logged. Common IPAM-related calls include operations like AssociateIpamResourceDiscovery, CreateIpamPool, and VPC association operations.

  4. Consider that the CIDR allocation might happen through VPC creation/modification API calls rather than direct IPAM API calls, especially if LZA is orchestrating the process.

Once you identify the correct event names from CloudTrail logs, update your EventBridge rule pattern accordingly. Your Lambda approach for backfilling the on-prem IPAM is sound - you just need to capture the right events.
Sources
AWS Lambda events - Amazon EventBridge

answered a month ago

EXPERT

reviewed a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.