Created
December 5, 2025 15:27
-
-
Save rleap-m/b54ff824d2977f7b95c63ae406e6c6ee to your computer and use it in GitHub Desktop.
PowerShell script which will return AWS EC2 VPC Peering objects for a given region
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| .SYNOPSIS | |
| Gets AWS VPC peering connections | |
| .DESCRIPTION | |
| Sometimes we use peering connections to connect VPCs (especially convenient to allow an MKE | |
| cluster to reach an LDAP server | |
| .PARAMETER Region | |
| AWS region where the VPCs reside | |
| .NOTES | |
| Author - rleap@mirantis.com | |
| .LINK | |
| Install PowerShell: https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-linux?view=powershell-7.5 | |
| .LINK | |
| Install AWS CLI Tool: https://aws.amazon.com/cli/ | |
| #> | |
| [CmdletBinding()] | |
| param ( | |
| [Parameter(Mandatory=$false)] | |
| [string] | |
| $Region = 'us-east-2' | |
| ) | |
| if (-not(Get-Command -Name 'aws' -ErrorAction SilentlyContinue)) { | |
| Write-Warning "This script requires the 'aws' cli tool (see https://aws.amazon.com/cli/). Exiting." | |
| return | |
| } | |
| $connections = @((aws ec2 describe-vpc-peering-connections --region $Region --output json --no-cli-pager | ConvertFrom-Json).VpcPeeringConnections) | |
| foreach ($connection in $connections) { | |
| [PSCustomObject]@{ | |
| Name = $connection.Tags.Value | |
| Id = $connection.VpcPeeringConnectionId | |
| AccepterVpcId = $connection.AccepterVpcInfo.VpcId | |
| AccepterCidr = $connection.AccepterVpcInfo.CidrBlock | |
| RequesterVpcId = $connection.RequesterVpcInfo.VpcId | |
| RequesterVpcCidr = $connection.RequesterVpcInfo.CidrBlock | |
| Status = $connection.Status.Code | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment