Closed hsuantio closed 5 years ago
Depends on feature request https://github.com/aws/aws-sdk-net/issues/1331.
The root cause of this is that the New-EC2LaunchTemplateVersion
cmdlet copies the value of SourceTemplateData
into LaunchTemplateData
performing the necessary conversion from type ResponseLaunchTemplateData
to type RequestLaunchTemplateData
. Because such conversion is performed by copying each field and optional integer fields return 0 when the field is not set, the resulting RequestLaunchTemplateData
always has Iops
set.
In order to address this, we need the AWS SDK for .NET to implement a way to distinguish unset value-type response fields (https://github.com/aws/aws-sdk-net/issues/1331 is tracking this request).
I cannot think of a good workaround for this issue, except for manually creating the RequestLaunchTemplateData
object and passing it to the LaunchTemplateData
parameter of New-EC2LaunchTemplateVersion
.
Hello, this issue is fixed with the latest release of AWSPowerShell 3.3.553.0.
We have also added a method in the SDK to check if a field is set in a service response (see https://github.com/aws/aws-sdk-net/issues/1331#issuecomment-513275696).
Please use that instead of the reflection-based workaround (... .GetMethods('NonPublic,Instance') | Where-Object Name -eq IsSetIops).Invoke ...
). The PowerShell syntax would be:
[Amazon.Util.AWSSDKUtils]::IsPropertySet($blockDeviceMapping.Ebs, 'Iops')
The
SourceTemplateData
parameter always setsAmazon.EC2.Model.LaunchTemplateEbsBlockDeviceRequest
IOPS value even though the original one is not. This causes launching EC2 instance with gp2 disk from the launch template to fail withThe parameter iops is not supported for gp2 volumes
error as the IOPS value is set.Expected Behavior
The
SourceTemplateData
parameter should not setAmazon.EC2.Model.LaunchTemplateEbsBlockDeviceRequest
IOPS value if the original isn't when mappingAmazon.EC2.Model.ResponseLaunchTemplateData
toAmazon.EC2.Model.RequestLaunchTemplateData
.Current Behavior The
SourceTemplateData
parameter always setsAmazon.EC2.Model.LaunchTemplateEbsBlockDeviceRequest
IOPS value even though the original one is not. This causes launching EC2 instance with gp2 disk from the launch template to fail withThe parameter iops is not supported for gp2 volumes
error as the IOPS value is set.Possible Solution
-SourceTemplateData
should not set the IOPS value if the original template data is not. The workaround is to manually mapAmazon.EC2.Model.ResponseLaunchTemplateData
toAmazon.EC2.Model.RequestLaunchTemplateData
and use-LaunchTemplateData
parameter instead.Steps to Reproduce (for bugs) Create LaunchTemplateEbsBlockDeviceRequest:
Create LaunchTemplateBlockDeviceMappingRequest:
Create RequestLaunchTemplateData:
Create EC2 launch template
Check if v1 launch template
__iops
is set usingIsSetIops()
method:Create LaunchTemplateSpecification:
Launch new EC2 instance from created launch template:
Create new launch template version from original
TestIssue2
as-is. This is launch template version 2.Check if v2 launch template
__iops
is set using IsSetIops() methodLet's see if I can apply a workaround
The new template data EBS IOPS should not be set now
So we now have a LaunchTemplateData which IOPS value is unset. Let's create a new launch template version using this one as v3.
For some reason, now the value is set to true when
-SourceTemplateData
maps values fromResponseLaunchTemplateData
toRequestLaunchTemplateData
Let's try to launch an EC2 instance using v3 launch template
Context Unable to implement launch template/versions automation using Powershell.
Your Environment