Created
December 22, 2021 07:40
-
-
Save FyberEngineers/2c1222abe51f05b8e9d11749a8a56161 to your computer and use it in GitHub Desktop.
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
eri := ec2.RunInstancesInput{ | |
DisableApiTermination: aws.Bool(false), | |
DryRun: aws.Bool(dryRun), //Set to true if you just want to test things out | |
IamInstanceProfile: &ec2.IamInstanceProfileSpecification{ | |
Name: aws.String("YOUR-IAM-PROFILE"), | |
}, | |
ImageId: aws.String("YOUR-AMI-WITH-DOCKER-EXPOSED"), | |
//The following sets the RunInstance request to use a spot instances | |
InstanceMarketOptions: &ec2.InstanceMarketOptionsRequest{ | |
MarketType: aws.String("spot"), | |
SpotOptions: &ec2.SpotMarketOptions{ | |
BlockDurationMinutes: aws.Int64(60), //Single hour | |
//MaxPrice: nil, //This can be set if required | |
SpotInstanceType: aws.String("one-time"), | |
}, | |
}, | |
InstanceType: aws.String("MACHINE-TYPE"), //i.e. c5a.12xlarge | |
KeyName: aws.String("SSH-KEYNAME-OR-NIL-STRING"), | |
MaxCount: aws.Int64(1), | |
MinCount: aws.Int64(1), | |
//The following describe the instance networking details | |
NetworkInterfaces: []*ec2.InstanceNetworkInterfaceSpecification{ | |
{ | |
AssociatePublicIpAddress: aws.Bool(true), | |
DeleteOnTermination: aws.Bool(true), | |
DeviceIndex: aws.Int64(0), | |
Groups: []*string{aws.String("YOUR-SG-FOR-THE-INSTANCE")}, | |
InterfaceType: aws.String("interface"), | |
SubnetId: aws.String("THE-SUBNET"), | |
}, | |
}, | |
//The following is extremely helpful for reporting | |
TagSpecifications: []*ec2.TagSpecification{{ | |
ResourceType: aws.String("instance"), | |
Tags: []*ec2.Tag{{ | |
Key: aws.String("environment"), | |
Value: aws.String("dev"), | |
}, | |
}}, | |
//optionally, if you need some boiler plate running on the instance run - | |
//UserData: aws.String("sudo apt install vim") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment