-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
138 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,50 @@ | ||
# Amazon Web Services | ||
|
||
Command Line Interface References: | ||
This page covers setting up the command-line interface for AWS services. | ||
For more information on AWS services, see one of these pages: | ||
|
||
- [AWS S3 CLI](https://docs.aws.amazon.com/cli/latest/reference/s3/index.html) | ||
- [AWS EC2 CLI](https://docs.aws.amazon.com/cli/latest/reference/ec2/index.html) | ||
- [AWS IAM CLI](https://docs.aws.amazon.com/cli/latest/reference/iam/index.html) | ||
- [AWS Glacier CLI](https://docs.aws.amazon.com/cli/latest/reference/glacier/index.html) | ||
- [S3](s3.md) | ||
- [EC2](ec2.md) | ||
- [IAM](iam.md) | ||
|
||
## Installation | ||
|
||
Fresh Ubuntu instances require [installation](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html): | ||
|
||
```sh | ||
#!/bin/bash | ||
# | ||
## Install AWS CLI v2 | ||
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | ||
unzip awscliv2.zip && sudo ./aws/install | ||
|
||
# cleanup | ||
rm -rf awscliv2.zip ./aws | ||
|
||
# add completion to your shell | ||
complete -C '/usr/local/bin/aws_completer' aws | ||
# on macOS, add the following to your .zshrc: | ||
# autoload bashcompinit && bashcompinit | ||
# autoload -Uz compinit && compinit | ||
|
||
# configure credentials; use the ones from the IAM user you created | ||
# AWS Access Key ID [None]: <YOUR_ACCESS_KEY_ID> | ||
# AWS Secret Access Key [None]: <YOUR_SECRET_ACCESS_KEY> | ||
# Default region name [None]: us-east-1 | ||
# Default output format [None]: [json|text|table] | ||
aws configure | ||
``` | ||
|
||
## Other CLI Tools | ||
|
||
### `ssh` | ||
|
||
edit `~/.ssh/config` | ||
unzip awscliv2.zip && sudo ./aws/install && rm -rf ./awscliv2.zip ./aws | ||
``` | ||
|
||
- add the location of the private key file so you don't have to specify it with `-i` each time you connect | ||
- add the `User` and `Hostname` fields so you don't have to specify them each time | ||
Next, add tab completion to your shell: | ||
|
||
```sh | ||
# example ~/.ssh/config | ||
Host aws | ||
Hostname ec2-1-234-5-6.compute-1.amazonaws.com | ||
User ubuntu | ||
IdentityFile ~/.ssh/aws.pem | ||
``` | ||
|
||
### `scp` | ||
|
||
- "secure copy" files between computers using `ssh` | ||
- this means the config from `~/.ssh/config` is used | ||
|
||
```sh | ||
# copy file to home dir of remote aws instance | ||
scp localfile.txt aws:~ | ||
|
||
# copy remote file to pwd | ||
scp aws:~/remotefile.txt . | ||
complete -C '/usr/local/bin/aws_completer' aws | ||
``` | ||
|
||
### `rsync` | ||
|
||
- useful for keeping all files in a directory up-to-date | ||
If you're using `zsh` (the shell on macOS), add the following to your `.zshrc` | ||
so that the completion script is loaded when you start a new shell: | ||
|
||
```sh | ||
# copy all files in a directory to a remote server | ||
rsync -avz --progress /path/to/local/dir/ aws:/path/to/remote/dir/ | ||
autoload bashcompinit && bashcompinit | ||
autoload -Uz compinit && compinit | ||
``` | ||
|
||
### `tmux` | ||
|
||
Weird stuff can happen with "nested" sessions over `ssh`. | ||
If you want to attach to a tmux session on a remote server, | ||
you need to use the `-t` flag since `tmux` is not a login shell. | ||
Finally, configure your credentials: | ||
|
||
```sh | ||
ssh aws # works | ||
ssh aws tmux a # huh? | ||
ssh aws -t tmux a # ok | ||
``` | ||
|
||
### `vim` | ||
|
||
Once you have ssh configured, you can use vim to edit files remotely thanks to | ||
the `netrw` plugin that comes shipped with `vim`. | ||
|
||
```sh | ||
vim scp://aws/remote/path/to/file | ||
aws configure | ||
``` | ||
|
||
Copy current vim buffer to remote server | ||
- AWS Access Key ID [None]: <YOUR_ACCESS_KEY_ID> | ||
- AWS Secret Access Key [None]: <YOUR_SECRET_ACCESS_KEY> | ||
- Default region name [None]: us-east-1 | ||
- Default output format [None]: [json|text|table] | ||
|
||
```vim | ||
:!scp % aws:~/path/to/remote/file | ||
``` | ||
## Further Reading | ||
Command Line Interface References: | ||
|
||
Inside vim, you can use the `:Explore` command to browse the remote server. | ||
Read more about it with `:h netrw` from inside vim. | ||
- [AWS S3 CLI](https://docs.aws.amazon.com/cli/latest/reference/s3/index.html) | ||
- [AWS EC2 CLI](https://docs.aws.amazon.com/cli/latest/reference/ec2/index.html) | ||
- [AWS IAM CLI](https://docs.aws.amazon.com/cli/latest/reference/iam/index.html) | ||
- [AWS Glacier CLI](https://docs.aws.amazon.com/cli/latest/reference/glacier/index.html) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.