Created
April 6, 2022 10:53
-
-
Save lzap/b8c3062b0973ba7a79a72d2785ac6465 to your computer and use it in GitHub Desktop.
Create an EC2 instance in Go SDK V2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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