go/ec2/README.md
These examples demonstrate how to perform several Amazon Elastic Compute Cloud (Amazon EC2) operations.
You must have an AWS account, and have your default credentials and AWS Region configured as described in Configuring the AWS SDK for Go in the AWS SDK for Go Developer Guide.
This example allocates a VPC Elastic IP address and associates it with an instance.
go run AllocateAddress.go -i INSTANCE-ID
The unit test mocks the service client and the AllocateAddress and AssociateAddress functions.
This example creates an Amazon EC2 image.
go run CreateImage -d IMAGE-DESCRIPTION -i INSTANCE-ID -n IMAGE-NAME
The unit test mocks the service client and the CreateImage function.
This example creates an Amazon EC2 instance.
go run CreateInstance -n NAME -v VALUE
The unit test mocks the service client and the RunInstances and CreateTags functions.
This example creates an Amazon EC2 key pair.
go run CreateKeyPair.go -k KEY-NAME
The unit test mocks the service client and the CreateKeyPair function.
This example creates a security group.
go run CreateSecurityGroup.go -n NAME -d DESCRIPTION [-v VPC-ID]
The unit test mocks the service client and the DescribeVpcs, CreateSecurityGroup, and AuthorizeSecurityGroupIngress functions.
This example deletes an Amazon EC2 key pair.
go run DeleteKeyPair.go -k KEY-NAME
The unit test mocks the service client and the DeleteKeyPair function.
This example deletes a security group.
go run DeleteSecurityGroup.go -n NAME
The unit test mocks the service client and the DeleteSecurityGroup function.
This example displays some information about the Elastic IP addresses for your account's VPC.
go run DescribeAddresses.go
This example lists your reservation IDs and instance IDs.
go run DescribeInstances.go
This example retrieves a list of Key Pairs stored in Amazon EC2.
go run DescribeKeyPairs.go
This example displays information about your security groups.
go run DescribeSecurityGroups.go
This example enables or disables monitoring for an instance.
go run MonitorInstances.go -i INSTANCE-ID -m STATE
The unit test mocks the service client and the MonitorInstances and UnmonitorInstances functions.
This example reboots an Amazon EC2 instance.
go run RebootInstances.go -i INSTANCE-ID
The unit test mocks the service client and the RebootInstances function.
This example lists the AWS Regions where Amazon EC2 is available, and the Availability Zones within the current AWS Region.
go run RegionsAndZones.go
This example releases an Elastic IP address. If the address is associated with an Amazon EC2 instance, the association is removed.
go run ReleaseAddress.go -a ALLOCATION-ID
The unit test mocks the service client and the ReleaseAddress function.
This example starts or stops an Amazon EC2 instance.
go run StartStopInstances.go -i INSTANCE-ID -s STATE
The unit test mocks the service client and the StartInstances and StopInstances functions.
Unit tests should delete any resources they create. However, they might result in charges to your AWS account.
To run a unit test, enter the following.
go test
You should see something like the following, where PATH is the path to the folder containing the Go files.
PASS
ok PATH 6.593s
To see any log messages, enter the following.
go test -test.v
You should see additional log messages. The last two lines should be similar to the previous output shown.
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0