SendSSHPublicKey - AWS EC2 Instance Connect

SendSSHPublicKey

Pushes an SSH public key to the specified EC2 instance for use by the specified user. The key remains for 60 seconds.

Request Syntax

{ "AvailabilityZone": "string", "InstanceId": "string", "InstanceOSUser": "string", "SSHPublicKey": "string" }

Request Parameters

For information about the parameters that are common to all actions, see Common Parameters.

The request accepts the following data in JSON format.

AvailabilityZone

The Availability Zone in which the EC2 instance was launched.

Type: String

Length Constraints: Minimum length of 6. Maximum length of 32.

Pattern: ^(\w+-){2,3}\d+\w+$

Required: Yes

InstanceId

The ID of the EC2 instance.

Type: String

Length Constraints: Minimum length of 10. Maximum length of 32.

Pattern: ^i-[a-f0-9]+$

Required: Yes

InstanceOSUser

The OS user on the EC2 instance for whom the key can be used to authenticate.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 32.

Pattern: ^[A-Za-z_][A-Za-z0-9\@\._-]{0,30}[A-Za-z0-9\$_-]?$

Required: Yes

SSHPublicKey

The public key material. To use the public key, you must have the matching private key.

Type: String

Length Constraints: Minimum length of 256. Maximum length of 4096.

Required: Yes

Response Syntax

{ "RequestId": "string", "Success": boolean }

Response Elements

If the action is successful, the service sends back an HTTP 200 response.

The following data is returned in JSON format by the service.

RequestId

The ID of the request. Please provide this ID when contacting AWS Support for assistance.

Type: String

Success

Is true if the request succeeds and an error otherwise.

Type: Boolean

Errors

For information about the errors that are common to all actions, see Common Errors.

AuthException

Either your AWS credentials are not valid or you do not have access to the EC2 instance.

HTTP Status Code: 400

EC2InstanceNotFoundException

The specified instance was not found in the specified Availability Zone.

HTTP Status Code: 400

InvalidArgsException

One of the parameters is not valid.

HTTP Status Code: 400

ServiceException

The service encountered an error. Follow the instructions in the error message and try again.

HTTP Status Code: 500

ThrottlingException

The requests were made too frequently and have been throttled. Wait a while and try again. To increase the limit on your request frequency, contact AWS Support.

HTTP Status Code: 400

Examples

Push an SSH public key to an instance

This example sends the specified SSH public key to the specified instance in the specified Availability Zone. The key is used to authenticate the specified user.

Sample Request

POST / HTTP/1.1 Content-Type: application/x-amz-json-1.1 X-Amz-Target: AWSEC2InstanceConnectService.SendSSHPublicKey { "AvailabilityZone": "us-east-2b", "InstanceId": "i-1234567890abcdef0", "InstanceOSUser": "ec2-user", "SSHPublicKey": "<ssh-public-key-material>" }

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: