Skip to content

Commit

Permalink
Allow EC2 instances to specify a key name
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Aug 31, 2023
1 parent 5d460da commit d1f5c7a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions provision/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func (p *EC2Provisioner) Provision(host BasicHost) (*ProvisionedHost, error) {

ports := host.Additional["ports"]

keyName := host.Additional["key-name"]

extraPorts, err := parsePorts(ports)
if err != nil {
return nil, err
Expand All @@ -69,8 +71,7 @@ func (p *EC2Provisioner) Provision(host BasicHost) (*ProvisionedHost, error) {
if len(subnetID) > 0 {
networkSpec.SubnetId = aws.String(subnetID)
}

runResult, err := p.ec2Provisioner.RunInstances(&ec2.RunInstancesInput{
runInput := &ec2.RunInstancesInput{
ImageId: image,
InstanceType: aws.String(host.Plan),
MinCount: aws.Int64(1),
Expand All @@ -79,7 +80,13 @@ func (p *EC2Provisioner) Provision(host BasicHost) (*ProvisionedHost, error) {
NetworkInterfaces: []*ec2.InstanceNetworkInterfaceSpecification{
&networkSpec,
},
})
}

if len(keyName) > 0 {
runInput.KeyName = aws.String(keyName)
}

runResult, err := p.ec2Provisioner.RunInstances(runInput)
if err != nil {
// clean up SG if there was an issue provisioning the EC2 instance
input := ec2.DeleteSecurityGroupInput{
Expand Down
File renamed without changes.

0 comments on commit d1f5c7a

Please sign in to comment.