Hi all! Do you know if there’s a good way to add a...
# aws
b
Hi all! Do you know if there’s a good way to add a key pair to an aws ec2 instance when deploying it? I am currently deploying all my infrastructure using my own key pair but I’d like it to be created with the key pair of my colleague also. Thanks a lot! 🐛
id recommend storing the public key in your config so you can reference it programatically rather than having it in the resource definition, looks a lot tidier
b
In fact I already did it for my key pair:
Copy code
# Import key pair
key_pair = aws.ec2.get_key_pair(
    key_name=config.require("key_name"),
)

server = aws.ec2.Instance(
    resource_name=resource_name,
    ami=ami.id,
    instance_type=size,
    key_name=config.require("key_name"),
    tags={
        "Name": instance_name,
    },
    vpc_security_group_ids=[group.id],
)
But I don’t find any easy way to also attribute the key pair of my colleague to the resource...
v
you cant add multiple key pairs, but you could do something like use the user data functionality to run a shell script to install the ssh key pairs for you
b
Okay, I’ll try that, thank you!
v
something along those lines
🙏 1
b
Thanks!
v
no problem 🙂