Create EC2 Keypair in CloudFormation template

0

I found CloudFormation template to create EC2 and all of them need to create EC2 Keypair first by console and link it to CF template. Do we have any way to create keypair in CF temaplate and use it for EC2?

질문됨 6달 전411회 조회
1개 답변
1

You can absolutely do this.

First, create the keypair: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-keypair.html

Then, when you are creating the instance you can reference the keypair: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-instance.html#cfn-ec2-instance-keyname

Edit (adding further details based on comment below): In the documentation on the page linked above it says this about downloading the newly created keypair:

When you create a new key pair, the private key is saved to AWS Systems Manager Parameter Store, using a parameter with the following name: /ec2/keypair/{key_pair_id}

profile pictureAWS
전문가
답변함 6달 전
profile picture
전문가
검토됨 6달 전
  • Thank you,{ "Resources": { "NewKeyPair": { "Type": "AWS::EC2::KeyPair", "Properties": { "KeyName": "MyKeyPair" } }, "Ec2Instance": { "Type": "AWS::EC2::Instance", "Properties": { "ImageId": "ami-02b92c281a4d3dc79", "KeyName": { "Ref": "NewKeyPair" } } } } } With above example, how can we download .pem file to connect to instance after launch? I found this example:

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠