

There are more AWS SDK examples available in the [AWS Doc SDK Examples](https://github.com/awsdocs/aws-doc-sdk-examples) GitHub repo.

# Amazon EC2 Instance Connect examples using AWS CLI
<a name="cli_2_ec2-instance-connect_code_examples"></a>

The following code examples show you how to perform actions and implement common scenarios by using the AWS Command Line Interface with Amazon EC2 Instance Connect.

*Actions* are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.

Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.

**Topics**
+ [Actions](#actions)

## Actions
<a name="actions"></a>

### `send-ssh-public-key`
<a name="ec2-instance-connect_SendSshPublicKey_cli_2_topic"></a>

The following code example shows how to use `send-ssh-public-key`.

**AWS CLI**  
**To send a an SSH public key to an instance**  
The following `send-ssh-public-key` example sends the specified SSH public key to the specified instance. The key is used to authenticate the specified user.  

```
aws ec2-instance-connect send-ssh-public-key \
    --instance-id {{i-1234567890abcdef0}} \
    --instance-os-user {{ec2-user}} \
    --availability-zone {{us-west-2b}} \
    --ssh-public-key {{file://path/my-rsa-key.pub}}
```
Contents of `my-rsa-key.pub`:  

```
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC1a2b3c4d5e6f7a8b9c0dEXAMPLEKEY ec2-user@example
```
This command produces no output.  
For more information, see [Connect to a Linux instance using EC2 Instance Connect](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-connect-methods.html) in the *Amazon EC2 User Guide*.  
+  For API details, see [SendSshPublicKey](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ec2-instance-connect/send-ssh-public-key.html) in *AWS CLI Command Reference*. 