Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect omission of supplied zero/false parameters in API calls #1223

Closed
3 tasks done
lnalex opened this issue Apr 11, 2021 · 2 comments
Closed
3 tasks done

Incorrect omission of supplied zero/false parameters in API calls #1223

lnalex opened this issue Apr 11, 2021 · 2 comments
Labels
bug This issue is a bug.

Comments

@lnalex
Copy link

lnalex commented Apr 11, 2021

Confirm by changing [ ] to [x] below to ensure that it's a bug:

Describe the bug
The SDK incorrectly omits zero/false values on some SDK client methods.

Version of AWS SDK for Go?
1.3.2

Version of Go (go version)?
go version go1.16.3 windows/amd64

To Reproduce (observed behavior)
Steps to reproduce the behavior (please share code or minimal repo)

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/service/ec2"
	"github.com/aws/aws-sdk-go-v2/service/ec2/types"
)

func main() {
	region := "ap-southeast-2"
	subnetId := "subnet-XXX"
	amiId := "ami-XXX"

	ctx := context.Background()
	cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion(region), config.WithClientLogMode(aws.LogRequestWithBody))
	if err != nil {
		log.Fatalf("failed to load aws config: %v", err)
	}
	ec2Client := ec2.NewFromConfig(cfg)
	_, err = ec2Client.RunInstances(ctx, &ec2.RunInstancesInput{
		MaxCount:     1,
		MinCount:     1,
		ImageId:      aws.String(amiId),
		InstanceType: types.InstanceTypeT3aMicro,
		NetworkInterfaces: []types.InstanceNetworkInterfaceSpecification{
			{
				DeviceIndex:              0,
				AssociatePublicIpAddress: false,
				Description:              aws.String("testing123"),
				SubnetId:                 aws.String(subnetId),
			},
		},
	})
	if err != nil {
		log.Fatal(err)
	}
}

Output:

<snip>

Action=RunInstances&ClientToken=<REDACTED>
	&ImageId=ami-XXX
	&InstanceType=t3a.micro
	&MaxCount=1
	&MinCount=1
	&NetworkInterface.1.Description=testing123
	&NetworkInterface.1.SubnetId=subnet-XXX
	&Version=2016-11-15

2021/04/11 23:13:42 operation error EC2: RunInstances, https response error StatusCode: 400, RequestID: <REDACTED>, api error InvalidParameterValue: Each network interface requires a device index.
exit status 1

(formatted with line breaks)
As seen from above, the AssociatePublicIpAddress and DeviceIndex parameters are omitted from the API call, making this API call invalid.

Didn't test thoroughly for other methods, but CreateLaunchTemplate also has the same problem.

Related issue #1203 also shows AuthorizeSecurityGroupIngress exhibiting the same issue.

_, err = ec2Client.AuthorizeSecurityGroupIngress(context.TODO(),
	&ec2.AuthorizeSecurityGroupIngressInput{
		GroupId: aws.String("sg-XXX"),
		IpPermissions: []types.IpPermission{
			{
				FromPort:   0,
				ToPort:     65535,
				IpProtocol: aws.String("tcp"),
				IpRanges: []types.IpRange{
					{
						CidrIp:      aws.String("0.0.0.0/0"),
						Description: aws.String("test"),
					},
				},
			},
		},
	},
)

Output:

<snip>

Action=AuthorizeSecurityGroupIngress
	&GroupId=sg-XXX
	&IpPermissions.1.IpProtocol=tcp
	&IpPermissions.1.IpRanges.1.CidrIp=0.0.0.0%2F0
	&IpPermissions.1.IpRanges.1.Description=test
	&IpPermissions.1.ToPort=65535
	&Version=2016-11-15

2021/04/11 23:08:02 operation error EC2: AuthorizeSecurityGroupIngress, https response error StatusCode: 400, RequestID: <REDACTED>, api error InvalidParameterValue: Invalid value 'Must specify both from and to ports with TCP/UDP.' for portRange.

IpPermissions.1.ToPort=0 should be included in the API call parameters, but is omitted by the SDK.

Expected behavior
Zero/false values should not be omitted by the SDK.

From a quick poke around for examples, the EKS UpdateClusterConfigInput takes a pointer (aws.Bool) instead of value, which seems to correctly result in the value being sent in the API call.

&eks.UpdateClusterConfigInput{
		Name: aws.String("managed-test"),
		Logging: &eksTypes.Logging{
			ClusterLogging: []eksTypes.LogSetup{
				{
					Types:   []eksTypes.LogType{eksTypes.LogTypeControllerManager},
					Enabled: aws.Bool(false),
				},
			},
		},
	}

Additional context
N/A

@lnalex lnalex added the bug This issue is a bug. label Apr 11, 2021
@lnalex
Copy link
Author

lnalex commented Apr 11, 2021

Seems to be fixed by PR #1195
Closing issue

@lnalex lnalex closed this as completed Apr 11, 2021
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

1 participant