Skip to content

Instantly share code, notes, and snippets.

@lzap
Created April 6, 2022 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lzap/b8c3062b0973ba7a79a72d2785ac6465 to your computer and use it in GitHub Desktop.
Save lzap/b8c3062b0973ba7a79a72d2785ac6465 to your computer and use it in GitHub Desktop.
Create an EC2 instance in Go SDK V2
func CreateInstance(client *ec2.Client) {
input := &ec2.RunInstancesInput{}
input.DryRun = aws.Bool(true)
input.ImageId = aws.String("ami-08c308b1bb265e927")
input.InstanceType = types.InstanceTypeT3Micro
input.MinCount = aws.Int32(1)
input.MaxCount = aws.Int32(1)
resp, err := client.RunInstances(context.TODO(), input)
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("Created reservation %s\n", *resp.ReservationId)
for _, i := range resp.Instances {
fmt.Printf("Instance %s is launching\n", *i.InstanceId)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment