A better way to do this would be to run AWS's Add-Routes function. But in order to do that, you need to import it first.
You can import it and run it on a one liner like this from powershell on your instance that is not getting the metadata accessible;
Import-Module c:\ProgramData\Amazon\EC2-Windows\Launch\Module\Ec2Launch.psm1 ; Add-Routes
This Add-Routes
function is what the InitializeInstance.ps1 script runs to fix the metadata.
FYI, I experience this issue all the time on Windows 2019 Server, and feel like its an issue on AWS side where sometimes instances spin up and don't complete the cloud init always. This is a much used command for ASG groups, etc..
The benefit of this over the @John Rotenstein answer, is that it will run only the routes, will not run the Initialize disks command, so will finish quicker.
One further note that may be good to add to this Post, is that there is two ways to get the instance metadata, the IMDSv1 method mentioned above may not work if your using IMDSv2. The proper way to get the metadata for IMDSv2 is
PS C:\> [string]$token = Invoke-RestMethod -Headers @{"X-aws-ec2-metadata-token-ttl-seconds" = "21600"} -Method PUT -Uri http://169.254.169.254/latest/api/token
PS C:\> Invoke-RestMethod -Headers @{"X-aws-ec2-metadata-token" = $token} -Method GET -Uri http://169.254.169.254/latest/meta-data/
Docs on that are here