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

How to create EC2 instance with public IP enabled #1190

Closed
2 tasks done
binchenX opened this issue Mar 21, 2021 · 4 comments
Closed
2 tasks done

How to create EC2 instance with public IP enabled #1190

binchenX opened this issue Mar 21, 2021 · 4 comments
Labels
bug This issue is a bug. service-api This issue is due to a problem in a service API, not the SDK implementation.

Comments

@binchenX
Copy link

binchenX commented Mar 21, 2021

Confirm by changing [ ] to [x] below:

Describe the question
Since the ec2.RunInstancesInput has not argument to enable the public IP, so I think one (1*) way is to 1) create an interface explicitly and 2) set the InstanceNetworkInterfaceSpecification.AssociatePublicIpAddress but I met following error:

Got an error creating an instance:
operation error EC2: RunInstances, https response error StatusCode: 400, RequestID: 44b3be40-64cb-4ee9-804a-88302c80db88, api error InvalidParameterValue: Each network interface requires a device index.

Below is the code snippet used (error check and other parts are removed for brevity. )

	network, err := client.CreateNetworkInterface(context.TODO(), &ec2.CreateNetworkInterfaceInput{
		SubnetId: subnetId,
		Groups: []string{sgID},
         })

	input := &ec2.RunInstancesInput{
		ImageId:      aws.String(AmiUbuntu),
		InstanceType: types.InstanceTypeT2Micro,
		KeyName:      aws.String(keyPair),
		MaxCount:     1,
		MinCount:     1,
		NetworkInterfaces: []types.InstanceNetworkInterfaceSpecification{
			{
				Description:              aws.String("the primary device eth0"),
				DeviceIndex:              0,
				NetworkInterfaceId:       network.NetworkInterface.NetworkInterfaceId,
				AssociatePublicIpAddress: true,
				SubnetId:                 subnetId,
				Groups:                   []string{sgID},
			},
		},

Not sure what is missing here and the error message doesn't quite help. Appreciate your help!


1* According to the doc, the other way is to enable the subnet attribute to let all the instance created in that subnet have an public IP automatically. I didn't do this way since 1) I don't want all the instance in that subnet to have an public IP and 2) I didn't see the option to have that attribute enabled when creating the subnet but I do see that attribute in the output of the subnet creating.

@binchenX binchenX added the guidance Question that needs advice or information. label Mar 21, 2021
@varnastadeus
Copy link

@binchenX I think this is related to #1178

@jasdel jasdel added bug This issue is a bug. service-api This issue is due to a problem in a service API, not the SDK implementation. and removed guidance Question that needs advice or information. labels Mar 22, 2021
@jasdel
Copy link
Contributor

jasdel commented Mar 22, 2021

Thanks for reaching out @binchenX. This issue is similar to #1107 Where the EC2 API model is missing metadata instructing the SDK how it should serialize these operations. We're working with the EC2 service team on how best to address these operations.

@jasdel
Copy link
Contributor

jasdel commented May 7, 2021

This issue has been resolved in #1195 in the latest release tag, service/ec2/v1.6.0. You can update your application to use the latest version with

go get -d github.com/aws/aws-sdk-go-v2/service/ec2@v1.6.0

While this release fixes the client to be able to send all request parameters to the API, a breaking change to the generated code was needed. The parameters like MaxCount, MinCount, and DeviceIndex are pointer types now, not values. You can use either addresses, or the aws.Int32 utilities to not need to create a local variable when assigning the value.

@jasdel jasdel closed this as completed May 7, 2021
@github-actions
Copy link

github-actions bot commented May 7, 2021

⚠️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. service-api This issue is due to a problem in a service API, not the SDK implementation.
Projects
None yet
Development

No branches or pull requests

3 participants