Error:
New-Object : Cannot find type [PutEventsRequestEntry]: verify that the assembly containing this type is loaded
Code:
$entry = New-Object -Type Amazon.EventBridge.Model.PutEventsRequestEntry
$entry.Detail = $detailObject
$entry.Source = "inbound"
$entry.DetailType = "record sent"
$entry.Time = Get-Date -Format "yyyy-MM-ddTHH:mm:ssZ"
Write-EVBEvent -Entry $events -Select "*"
I have AWS.Tools.Common and AWS.Tools.EventBridge modules installed via this command:
Install-Module -Name AWS.Tools.EventBridge
And I can see them listed with this command:
Get-Module -ListAvailable
This code was originally working, I'm not sure what has changed. It's on a WorkSpaces instance though, so anything might have happened.
Do I need to Install the AWS SDK as well?
https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/EventBridge/TPutEventsRequestEntry.html
I tried to install like this:
Install-Package AWSSDK.EventBridge -Version 3.7.5.29
No match was found for the specified search criteria and package name 'AWSSDK.EventBridge'
I tried installing the assembly like this:
Download SDK from here: https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/net-dg-obtain-assemblies.html
Move the AWSSDK.EventBridge.dll and AWSSDK.Core.dll files to the script root, and unblock the file in properties.
Load the library:
Add-Type -LiteralPath "./AWSSDK.Core.dll"
Add-Type -LiteralPath "./AWSSDK.EventBridge.dll"
But I still get the same error related to the PutEventsRequestEntry object.
Edit: I removed all associated libraries, and reinstalled using this command:
Install-Module -Name AWS.Tools.Installer
Install-AWSToolsModule -Name EventBridge -CleanUp
No change though.
This is a known issue with AWS PowerShell tools and PowerShell 5, with no clear resolution, other than upgrading to PowerShell 7, or continually reinstalling until it works...
The issue self-resolves by itself after multiple retries to install a module.
Even under PS7 I still had issues, and need to run this command also:
Import-Module AWS.Tools.EventBridge
Some details here: