AWS Lightsail Key Pair
This page shows how to write Terraform and CloudFormation for Lightsail Key Pair and write them securely.
aws_lightsail_key_pair (Terraform)
The Key Pair in Lightsail can be configured in Terraform with the resource name aws_lightsail_key_pair. The following sections describe 5 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_lightsail_key_pair" "default" {
name = "wordpress"
}
resource "aws_lightsail_static_ip" "default" {
name = "wordpress"
resource "aws_lightsail_key_pair" "lightsail_nex4" {
name = "lightsail_nex4"
}
# create static ip
resource "aws_lightsail_static_ip" "test" {
resource "aws_lightsail_key_pair" "ssh_keys" {
count = length(var.ssh_keys)
name = element(keys(var.ssh_keys), count.index)
public_key = element(values(var.ssh_keys), count.index)
}
resource "aws_lightsail_key_pair" "key_pair" {
name = "lg_key_pair"
}
resource "aws_lightsail_key_pair" "template_access" {
name = "template-access"
public_key = file("./template-access.pub")
}
Parameters
-
arnoptional computed - string -
encrypted_fingerprintoptional computed - string -
encrypted_private_keyoptional computed - string -
fingerprintoptional computed - string -
idoptional computed - string -
nameoptional computed - string -
name_prefixoptional - string -
pgp_keyoptional - string -
private_keyoptional computed - string -
public_keyoptional computed - string
Explanation in Terraform Registry
Provides a Lightsail Key Pair, for use with Lightsail Instances. These key pairs are separate from EC2 Key Pairs, and must be created or imported for use with Lightsail.
Note: Lightsail is currently only supported in a limited number of AWS Regions, please see "Regions and Availability Zones in Amazon Lightsail" for more details
AWS::Lightsail::Instance (CloudFormation)
The Instance in Lightsail can be configured in CloudFormation with the resource name AWS::Lightsail::Instance. The following sections describe 2 examples of how to use the resource and its parameters.
Example Usage from GitHub
Type: AWS::Lightsail::Instance
Properties:
BlueprintId: !Ref BluePrintId
BundleId: !Ref BundleId
InstanceName: !Ref InstanceName
Networking:
Type: AWS::Lightsail::Instance
CreationPolicy:
ResourceSignal:
Timeout: PT15M
Properties:
BlueprintId: ubuntu_20_04
Parameters
-
Locationoptional - Location -
Hardwareoptional - Hardware -
Stateoptional - State -
Networkingoptional - Networking -
InstanceNamerequired - String -
AvailabilityZoneoptional - String -
BundleIdrequired - String -
BlueprintIdrequired - String -
AddOnsoptional - List of AddOn -
UserDataoptional - String -
KeyPairNameoptional - String -
Tagsoptional - List of Tag
Explanation in CloudFormation Registry
The
AWS::Lightsail::Instanceresource specifies an Amazon Lightsail instance.
Frequently asked questions
What is AWS Lightsail Key Pair?
AWS Lightsail Key Pair is a resource for Lightsail of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.
Where can I find the example code for the AWS Lightsail Key Pair?
For Terraform, the devops-adeel/wordpress, Htunn/IaC_Terraform and fdm1/terraform-ansible source code examples are useful. See the Terraform Example section for further details.
For CloudFormation, the allendcanning/cloudformation and AlexMikhalochkin/jarvis source code examples are useful. See the CloudFormation Example section for further details.