published on Tuesday, Mar 10, 2026 by Pulumi
published on Tuesday, Mar 10, 2026 by Pulumi
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
Example Usage
Create New Key Pair
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
// Create a new Lightsail Key Pair
var lgKeyPair = new Aws.LightSail.KeyPair("lgKeyPair");
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/lightsail"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := lightsail.NewKeyPair(ctx, "lgKeyPair", nil)
if err != nil {
return err
}
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.lightsail.KeyPair;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var lgKeyPair = new KeyPair("lgKeyPair");
}
}
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// Create a new Lightsail Key Pair
const lgKeyPair = new aws.lightsail.KeyPair("lgKeyPair", {});
import pulumi
import pulumi_aws as aws
# Create a new Lightsail Key Pair
lg_key_pair = aws.lightsail.KeyPair("lgKeyPair")
resources:
# Create a new Lightsail Key Pair
lgKeyPair:
type: aws:lightsail:KeyPair
Create New Key Pair with PGP Encrypted Private Key
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var lgKeyPair = new Aws.LightSail.KeyPair("lgKeyPair", new()
{
PgpKey = "keybase:keybaseusername",
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/lightsail"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := lightsail.NewKeyPair(ctx, "lgKeyPair", &lightsail.KeyPairArgs{
PgpKey: pulumi.String("keybase:keybaseusername"),
})
if err != nil {
return err
}
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.lightsail.KeyPair;
import com.pulumi.aws.lightsail.KeyPairArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var lgKeyPair = new KeyPair("lgKeyPair", KeyPairArgs.builder()
.pgpKey("keybase:keybaseusername")
.build());
}
}
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const lgKeyPair = new aws.lightsail.KeyPair("lgKeyPair", {pgpKey: "keybase:keybaseusername"});
import pulumi
import pulumi_aws as aws
lg_key_pair = aws.lightsail.KeyPair("lgKeyPair", pgp_key="keybase:keybaseusername")
resources:
lgKeyPair:
type: aws:lightsail:KeyPair
properties:
pgpKey: keybase:keybaseusername
Existing Public Key Import
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var lgKeyPair = new Aws.LightSail.KeyPair("lgKeyPair", new()
{
PublicKey = File.ReadAllText("~/.ssh/id_rsa.pub"),
});
});
package main
import (
"os"
"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/lightsail"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func readFileOrPanic(path string) pulumi.StringPtrInput {
data, err := os.ReadFile(path)
if err != nil {
panic(err.Error())
}
return pulumi.String(string(data))
}
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := lightsail.NewKeyPair(ctx, "lgKeyPair", &lightsail.KeyPairArgs{
PublicKey: readFileOrPanic("~/.ssh/id_rsa.pub"),
})
if err != nil {
return err
}
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.lightsail.KeyPair;
import com.pulumi.aws.lightsail.KeyPairArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var lgKeyPair = new KeyPair("lgKeyPair", KeyPairArgs.builder()
.publicKey(Files.readString(Paths.get("~/.ssh/id_rsa.pub")))
.build());
}
}
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as fs from "fs";
const lgKeyPair = new aws.lightsail.KeyPair("lgKeyPair", {publicKey: fs.readFileSync("~/.ssh/id_rsa.pub")});
import pulumi
import pulumi_aws as aws
lg_key_pair = aws.lightsail.KeyPair("lgKeyPair", public_key=(lambda path: open(path).read())("~/.ssh/id_rsa.pub"))
resources:
lgKeyPair:
type: aws:lightsail:KeyPair
properties:
publicKey:
fn::readFile: ~/.ssh/id_rsa.pub
Create KeyPair Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new KeyPair(name: string, args?: KeyPairArgs, opts?: CustomResourceOptions);@overload
def KeyPair(resource_name: str,
args: Optional[KeyPairArgs] = None,
opts: Optional[ResourceOptions] = None)
@overload
def KeyPair(resource_name: str,
opts: Optional[ResourceOptions] = None,
name: Optional[str] = None,
name_prefix: Optional[str] = None,
pgp_key: Optional[str] = None,
public_key: Optional[str] = None)func NewKeyPair(ctx *Context, name string, args *KeyPairArgs, opts ...ResourceOption) (*KeyPair, error)public KeyPair(string name, KeyPairArgs? args = null, CustomResourceOptions? opts = null)
public KeyPair(String name, KeyPairArgs args)
public KeyPair(String name, KeyPairArgs args, CustomResourceOptions options)
type: aws:lightsail:KeyPair
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.
Parameters
- name string
- The unique name of the resource.
- args KeyPairArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- resource_name str
- The unique name of the resource.
- args KeyPairArgs
- The arguments to resource properties.
- opts ResourceOptions
- Bag of options to control resource's behavior.
- ctx Context
- Context object for the current deployment.
- name string
- The unique name of the resource.
- args KeyPairArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args KeyPairArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args KeyPairArgs
- The arguments to resource properties.
- options CustomResourceOptions
- Bag of options to control resource's behavior.
Constructor example
The following reference example uses placeholder values for all input properties.
var awsKeyPairResource = new Aws.LightSail.KeyPair("awsKeyPairResource", new()
{
Name = "string",
NamePrefix = "string",
PgpKey = "string",
PublicKey = "string",
});
example, err := lightsail.NewKeyPair(ctx, "awsKeyPairResource", &lightsail.KeyPairArgs{
Name: pulumi.String("string"),
NamePrefix: pulumi.String("string"),
PgpKey: pulumi.String("string"),
PublicKey: pulumi.String("string"),
})
var awsKeyPairResource = new com.pulumi.aws.lightsail.KeyPair("awsKeyPairResource", com.pulumi.aws.lightsail.KeyPairArgs.builder()
.name("string")
.namePrefix("string")
.pgpKey("string")
.publicKey("string")
.build());
aws_key_pair_resource = aws.lightsail.KeyPair("awsKeyPairResource",
name="string",
name_prefix="string",
pgp_key="string",
public_key="string")
const awsKeyPairResource = new aws.lightsail.KeyPair("awsKeyPairResource", {
name: "string",
namePrefix: "string",
pgpKey: "string",
publicKey: "string",
});
type: aws:lightsail:KeyPair
properties:
name: string
namePrefix: string
pgpKey: string
publicKey: string
KeyPair Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.
Inputs
In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.
The KeyPair resource accepts the following input properties:
- Name string
- The name of the Lightsail Key Pair. If omitted, a unique name will be generated by this provider
- Name
Prefix string - Pgp
Key string - An optional PGP key to encrypt the resulting private key material. Only used when creating a new key pair
- Public
Key string The public key material. This public key will be imported into Lightsail
NOTE: a PGP key is not required, however it is strongly encouraged. Without a PGP key, the private key material will be stored in state unencrypted.
pgp_keyis ignored ifpublic_keyis supplied.
- Name string
- The name of the Lightsail Key Pair. If omitted, a unique name will be generated by this provider
- Name
Prefix string - Pgp
Key string - An optional PGP key to encrypt the resulting private key material. Only used when creating a new key pair
- Public
Key string The public key material. This public key will be imported into Lightsail
NOTE: a PGP key is not required, however it is strongly encouraged. Without a PGP key, the private key material will be stored in state unencrypted.
pgp_keyis ignored ifpublic_keyis supplied.
- name String
- The name of the Lightsail Key Pair. If omitted, a unique name will be generated by this provider
- name
Prefix String - pgp
Key String - An optional PGP key to encrypt the resulting private key material. Only used when creating a new key pair
- public
Key String The public key material. This public key will be imported into Lightsail
NOTE: a PGP key is not required, however it is strongly encouraged. Without a PGP key, the private key material will be stored in state unencrypted.
pgp_keyis ignored ifpublic_keyis supplied.
- name string
- The name of the Lightsail Key Pair. If omitted, a unique name will be generated by this provider
- name
Prefix string - pgp
Key string - An optional PGP key to encrypt the resulting private key material. Only used when creating a new key pair
- public
Key string The public key material. This public key will be imported into Lightsail
NOTE: a PGP key is not required, however it is strongly encouraged. Without a PGP key, the private key material will be stored in state unencrypted.
pgp_keyis ignored ifpublic_keyis supplied.
- name str
- The name of the Lightsail Key Pair. If omitted, a unique name will be generated by this provider
- name_
prefix str - pgp_
key str - An optional PGP key to encrypt the resulting private key material. Only used when creating a new key pair
- public_
key str The public key material. This public key will be imported into Lightsail
NOTE: a PGP key is not required, however it is strongly encouraged. Without a PGP key, the private key material will be stored in state unencrypted.
pgp_keyis ignored ifpublic_keyis supplied.
- name String
- The name of the Lightsail Key Pair. If omitted, a unique name will be generated by this provider
- name
Prefix String - pgp
Key String - An optional PGP key to encrypt the resulting private key material. Only used when creating a new key pair
- public
Key String The public key material. This public key will be imported into Lightsail
NOTE: a PGP key is not required, however it is strongly encouraged. Without a PGP key, the private key material will be stored in state unencrypted.
pgp_keyis ignored ifpublic_keyis supplied.
Outputs
All input properties are implicitly available as output properties. Additionally, the KeyPair resource produces the following output properties:
- Arn string
- The ARN of the Lightsail key pair
- Encrypted
Fingerprint string - The MD5 public key fingerprint for the encrypted private key
- Encrypted
Private stringKey - the private key material, base 64 encoded and
encrypted with the given
pgp_key. This is only populated when creating a new key andpgp_keyis supplied - Fingerprint string
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- Id string
- The provider-assigned unique ID for this managed resource.
- Private
Key string - the private key, base64 encoded. This is only populated
when creating a new key, and when no
pgp_keyis provided
- Arn string
- The ARN of the Lightsail key pair
- Encrypted
Fingerprint string - The MD5 public key fingerprint for the encrypted private key
- Encrypted
Private stringKey - the private key material, base 64 encoded and
encrypted with the given
pgp_key. This is only populated when creating a new key andpgp_keyis supplied - Fingerprint string
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- Id string
- The provider-assigned unique ID for this managed resource.
- Private
Key string - the private key, base64 encoded. This is only populated
when creating a new key, and when no
pgp_keyis provided
- arn String
- The ARN of the Lightsail key pair
- encrypted
Fingerprint String - The MD5 public key fingerprint for the encrypted private key
- encrypted
Private StringKey - the private key material, base 64 encoded and
encrypted with the given
pgp_key. This is only populated when creating a new key andpgp_keyis supplied - fingerprint String
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- id String
- The provider-assigned unique ID for this managed resource.
- private
Key String - the private key, base64 encoded. This is only populated
when creating a new key, and when no
pgp_keyis provided
- arn string
- The ARN of the Lightsail key pair
- encrypted
Fingerprint string - The MD5 public key fingerprint for the encrypted private key
- encrypted
Private stringKey - the private key material, base 64 encoded and
encrypted with the given
pgp_key. This is only populated when creating a new key andpgp_keyis supplied - fingerprint string
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- id string
- The provider-assigned unique ID for this managed resource.
- private
Key string - the private key, base64 encoded. This is only populated
when creating a new key, and when no
pgp_keyis provided
- arn str
- The ARN of the Lightsail key pair
- encrypted_
fingerprint str - The MD5 public key fingerprint for the encrypted private key
- encrypted_
private_ strkey - the private key material, base 64 encoded and
encrypted with the given
pgp_key. This is only populated when creating a new key andpgp_keyis supplied - fingerprint str
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- id str
- The provider-assigned unique ID for this managed resource.
- private_
key str - the private key, base64 encoded. This is only populated
when creating a new key, and when no
pgp_keyis provided
- arn String
- The ARN of the Lightsail key pair
- encrypted
Fingerprint String - The MD5 public key fingerprint for the encrypted private key
- encrypted
Private StringKey - the private key material, base 64 encoded and
encrypted with the given
pgp_key. This is only populated when creating a new key andpgp_keyis supplied - fingerprint String
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- id String
- The provider-assigned unique ID for this managed resource.
- private
Key String - the private key, base64 encoded. This is only populated
when creating a new key, and when no
pgp_keyis provided
Look up Existing KeyPair Resource
Get an existing KeyPair resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.
public static get(name: string, id: Input<ID>, state?: KeyPairState, opts?: CustomResourceOptions): KeyPair@staticmethod
def get(resource_name: str,
id: str,
opts: Optional[ResourceOptions] = None,
arn: Optional[str] = None,
encrypted_fingerprint: Optional[str] = None,
encrypted_private_key: Optional[str] = None,
fingerprint: Optional[str] = None,
name: Optional[str] = None,
name_prefix: Optional[str] = None,
pgp_key: Optional[str] = None,
private_key: Optional[str] = None,
public_key: Optional[str] = None) -> KeyPairfunc GetKeyPair(ctx *Context, name string, id IDInput, state *KeyPairState, opts ...ResourceOption) (*KeyPair, error)public static KeyPair Get(string name, Input<string> id, KeyPairState? state, CustomResourceOptions? opts = null)public static KeyPair get(String name, Output<String> id, KeyPairState state, CustomResourceOptions options)resources: _: type: aws:lightsail:KeyPair get: id: ${id}- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- resource_name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- Arn string
- The ARN of the Lightsail key pair
- Encrypted
Fingerprint string - The MD5 public key fingerprint for the encrypted private key
- Encrypted
Private stringKey - the private key material, base 64 encoded and
encrypted with the given
pgp_key. This is only populated when creating a new key andpgp_keyis supplied - Fingerprint string
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- Name string
- The name of the Lightsail Key Pair. If omitted, a unique name will be generated by this provider
- Name
Prefix string - Pgp
Key string - An optional PGP key to encrypt the resulting private key material. Only used when creating a new key pair
- Private
Key string - the private key, base64 encoded. This is only populated
when creating a new key, and when no
pgp_keyis provided - Public
Key string The public key material. This public key will be imported into Lightsail
NOTE: a PGP key is not required, however it is strongly encouraged. Without a PGP key, the private key material will be stored in state unencrypted.
pgp_keyis ignored ifpublic_keyis supplied.
- Arn string
- The ARN of the Lightsail key pair
- Encrypted
Fingerprint string - The MD5 public key fingerprint for the encrypted private key
- Encrypted
Private stringKey - the private key material, base 64 encoded and
encrypted with the given
pgp_key. This is only populated when creating a new key andpgp_keyis supplied - Fingerprint string
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- Name string
- The name of the Lightsail Key Pair. If omitted, a unique name will be generated by this provider
- Name
Prefix string - Pgp
Key string - An optional PGP key to encrypt the resulting private key material. Only used when creating a new key pair
- Private
Key string - the private key, base64 encoded. This is only populated
when creating a new key, and when no
pgp_keyis provided - Public
Key string The public key material. This public key will be imported into Lightsail
NOTE: a PGP key is not required, however it is strongly encouraged. Without a PGP key, the private key material will be stored in state unencrypted.
pgp_keyis ignored ifpublic_keyis supplied.
- arn String
- The ARN of the Lightsail key pair
- encrypted
Fingerprint String - The MD5 public key fingerprint for the encrypted private key
- encrypted
Private StringKey - the private key material, base 64 encoded and
encrypted with the given
pgp_key. This is only populated when creating a new key andpgp_keyis supplied - fingerprint String
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- name String
- The name of the Lightsail Key Pair. If omitted, a unique name will be generated by this provider
- name
Prefix String - pgp
Key String - An optional PGP key to encrypt the resulting private key material. Only used when creating a new key pair
- private
Key String - the private key, base64 encoded. This is only populated
when creating a new key, and when no
pgp_keyis provided - public
Key String The public key material. This public key will be imported into Lightsail
NOTE: a PGP key is not required, however it is strongly encouraged. Without a PGP key, the private key material will be stored in state unencrypted.
pgp_keyis ignored ifpublic_keyis supplied.
- arn string
- The ARN of the Lightsail key pair
- encrypted
Fingerprint string - The MD5 public key fingerprint for the encrypted private key
- encrypted
Private stringKey - the private key material, base 64 encoded and
encrypted with the given
pgp_key. This is only populated when creating a new key andpgp_keyis supplied - fingerprint string
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- name string
- The name of the Lightsail Key Pair. If omitted, a unique name will be generated by this provider
- name
Prefix string - pgp
Key string - An optional PGP key to encrypt the resulting private key material. Only used when creating a new key pair
- private
Key string - the private key, base64 encoded. This is only populated
when creating a new key, and when no
pgp_keyis provided - public
Key string The public key material. This public key will be imported into Lightsail
NOTE: a PGP key is not required, however it is strongly encouraged. Without a PGP key, the private key material will be stored in state unencrypted.
pgp_keyis ignored ifpublic_keyis supplied.
- arn str
- The ARN of the Lightsail key pair
- encrypted_
fingerprint str - The MD5 public key fingerprint for the encrypted private key
- encrypted_
private_ strkey - the private key material, base 64 encoded and
encrypted with the given
pgp_key. This is only populated when creating a new key andpgp_keyis supplied - fingerprint str
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- name str
- The name of the Lightsail Key Pair. If omitted, a unique name will be generated by this provider
- name_
prefix str - pgp_
key str - An optional PGP key to encrypt the resulting private key material. Only used when creating a new key pair
- private_
key str - the private key, base64 encoded. This is only populated
when creating a new key, and when no
pgp_keyis provided - public_
key str The public key material. This public key will be imported into Lightsail
NOTE: a PGP key is not required, however it is strongly encouraged. Without a PGP key, the private key material will be stored in state unencrypted.
pgp_keyis ignored ifpublic_keyis supplied.
- arn String
- The ARN of the Lightsail key pair
- encrypted
Fingerprint String - The MD5 public key fingerprint for the encrypted private key
- encrypted
Private StringKey - the private key material, base 64 encoded and
encrypted with the given
pgp_key. This is only populated when creating a new key andpgp_keyis supplied - fingerprint String
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- name String
- The name of the Lightsail Key Pair. If omitted, a unique name will be generated by this provider
- name
Prefix String - pgp
Key String - An optional PGP key to encrypt the resulting private key material. Only used when creating a new key pair
- private
Key String - the private key, base64 encoded. This is only populated
when creating a new key, and when no
pgp_keyis provided - public
Key String The public key material. This public key will be imported into Lightsail
NOTE: a PGP key is not required, however it is strongly encouraged. Without a PGP key, the private key material will be stored in state unencrypted.
pgp_keyis ignored ifpublic_keyis supplied.
Import
Lightsail Key Pairs cannot be imported, because the private and public key are only available on initial creation.
To learn more about importing existing cloud resources, see Importing resources.
Package Details
- Repository
- AWS Classic pulumi/pulumi-aws
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
awsTerraform Provider.
published on Tuesday, Mar 10, 2026 by Pulumi
