aws cli

AWS CLI v2

AWS Command Line Interface 빠른 참조 — 자격 증명 설정, IAM 신원, EC2 / Lambda / S3 / DynamoDB / IAM, 프로파일, SSO, 페이징 / 출력 형식 — 자주 쓰는 옵션과 실전 예시까지 함께 정리했습니다.

명령어 40개

도움말

aws --version

awscli 버전을 출력합니다(v2.x).

aws --version
aws help

최상위 도움말 — 서비스 그룹과 기본 사용법을 나열합니다.

aws help
aws <service> help

한 서비스의 명령을 표시합니다.

<service> help; aws <service> <command> help

aws s3 help
aws <service> <command> help

단일 API 호출의 모든 플래그 + 매개변수를 표시합니다.

aws ec2 run-instances help
aws <service> <command> --generate-cli-skeleton

명령의 모든 필수 / 선택 필드를 가진 JSON 스켈레톤을 출력합니다 — 입력으로 다시 붙여넣으세요.

--generate-cli-skeleton <input|output>; --cli-input-json <file>; --cli-input-yaml <file>

aws ec2 run-instances --generate-cli-skeleton > ec2.json

설정

aws configure

인터랙티브 마법사 — `~/.aws/credentials`와 `~/.aws/config`에 액세스 키, 시크릿, 출력 형식, region을 설정합니다.

aws configure
aws configure --profile <name>

`aws configure`와 같지만 명명된 프로파일에 기록합니다.

--profile dev; --profile prod; --no-prompt

aws configure --profile prod
aws configure get <key>

활성 설정에서 단일 값을 읽습니다.

default.region; default.output; <key>; --profile <name>

aws configure get region --profile prod
aws configure set <key> <value>

단일 설정 값을 설정합니다.

<key> <value>; --profile <name>

aws configure set region us-west-2
aws configure list

활성 설정을 표시합니다(프로파일, region, 액세스 키 ID, 시크릿은 마스킹).

aws configure list

SSO / 신원

aws sso login --profile <name>

SSO 디바이스 흐름 로그인(또는 브라우저 리다이렉트)을 시작합니다. 프로파일에 단기 자격 증명을 설정합니다.

--profile dev; --no-browser; --use-device-code

aws sso login --profile dev
aws sso configure

SSO 프로파일을 인터랙티브하게 설정합니다(시작 URL, region, 계정, 역할).

aws sso configure
aws sts get-caller-identity

활성 자격 증명의 IAM 보안 주체(account / arn / user-id)를 출력합니다 — 설정 후 sanity check.

--profile <name>; --no-verify-ssl; --endpoint-url <url>

aws sts get-caller-identity
aws sts assume-role --role-arn <arn> --role-session-name <name>

IAM 역할로 전환해 임시 자격 증명을 받습니다 — 교차 계정 접근에 유용합니다.

--role-arn; --role-session-name; --external-id; --mfa-serial <arn>; --serial-number <arn>; --token-code <mfa>

aws sts assume-role --role-arn arn:aws:iam::123456789012:role/Admin --role-session-name admin

출력

aws <service> <command> --output <format>

출력 형식을 선택합니다: `json`(기본), `text`, `table`. jq 스타일 프로젝션에는 `--query`와 결합하세요.

json; text; table; yaml; yaml-stream

aws ec2 describe-instances --output table
aws <service> <command> --query '<JMES>'

JMESPath 표현식(jq 스타일)으로 응답을 프로젝션합니다.

--query 'Reservations[].Instances[].InstanceId'; --query 'Reservations[].Instances[].[InstanceId,State.Name]'

aws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId,State.Name]' --output table
aws <service> <command> --no-paginate

자동 페이징을 비활성화합니다 — 첫 페이지만 반환합니다(빠름; 개수만 필요할 때 유용).

aws s3 ls --no-paginate
aws <service> <command> --cli-binary-format raw-in-base64-out

입력 매개변수를 base64로 읽습니다 — `--zip-file fileb://lambda.zip` 같은 바이너리 매개변수에 필요합니다.

raw-in-base64-out; base64

aws lambda update-function-code --function-name fn --zip-file fileb://out.zip --cli-binary-format raw-in-base64-out

EC2

aws ec2 describe-instances

모든 EC2 인스턴스를 전체 세부사항과 함께 나열합니다.

--instance-ids i-xxx; --filters Name=tag:Name,Values=prod; --query; --output

aws ec2 describe-instances --query 'Reservations[].Instances[].{ID:InstanceId,State:State.Name}' --output table
aws ec2 start-instances --instance-ids <id>

중지된 인스턴스 하나 이상을 시작합니다.

--instance-ids i-xxx i-yyy

aws ec2 start-instances --instance-ids i-0abc123
aws ec2 stop-instances --instance-ids <id>

실행 중인 인스턴스 하나 이상을 중지합니다(종료 없이).

aws ec2 stop-instances --instance-ids i-0abc123
aws ec2 create-key-pair --key-name <name> --query 'KeyMaterial' --output text > key.pem

새 SSH 키 쌍을 만들고 올바른 권한으로 개인 키를 `.pem` 파일에 저장합니다.

aws ec2 create-key-pair --key-name dev --query 'KeyMaterial' --output text > dev.pem && chmod 400 dev.pem

S3

aws s3 ls

(인자 없이) 버킷을 또는 프리픽�스의 파일을 나열합니다.

s3://<bucket>/<prefix>; --recursive; --human-readable; --summarize

aws s3 ls s3://my-bucket/data/
aws s3 cp <local> s3://<bucket>/<key>

파일을 업로드 또는 복사합니다. `s3://...`는 소스 또는 대상이 될 수 있습니다.

--recursive; --exclude '*'; --include '*.log'; --storage-class STANDARD|GLACIER|...; --acl public-read

aws s3 cp ./build/ s3://my-bucket/release/ --recursive
aws s3 sync <src> s3://<bucket>/<dst>

S3 디렉터리 양방향 동기화(새로 / 변경된 파일을 업로드하고, `--delete`가 없으면 대상 측 추가 파일은 삭제하지 않음).

--delete; --exclude; --include; --no-progress; --exact-timestamps

aws s3 sync ./dist s3://my-bucket/app/ --delete
aws s3 mb s3://<bucket>

새 S3 버킷을 만듭니다. Region 기본값은 us-east-1이며 재정의하려면 `--region`을 전달하세요.

--region eu-west-1

aws s3 mb s3://my-new-bucket --region eu-west-1
aws s3 rb s3://<bucket>

버킷을 제거합니다(먼저 객체를 비우려면 `--force` 사용).

--force; --no-progress

aws s3 rb s3://old-bucket --force
aws s3 presign s3://<bucket>/<key> --expires-in <seconds>

`<seconds>` 후에 만료되는 사전 서명된 URL을 생성합니다 — 비공개 파일 공유에 유용합니다.

aws s3 presign s3://my-bucket/file.pdf --expires-in 3600

Lambda

aws lambda list-functions

현재 region의 모든 Lambda 함수를 나열합니다.

--function-version ALL; --max-items 50; --query 'Functions[].FunctionName'

aws lambda list-functions --query 'Functions[].FunctionName' --output text
aws lambda update-function-code --function-name <name> --zip-file fileb://fn.zip

로컬 zip에서 함수 코드를 업데이트합니다. 일부 설정에서는 `--cli-binary-format raw-in-base64-out`을 사용하세요.

aws lambda update-function-code --function-name my-fn --zip-file fileb://out.zip --cli-binary-format raw-in-base64-out
aws lambda invoke --function-name <name> --payload '{}' out.json

함수를 동기적으로 호출합니다 — 응답을 `out.json`에 씁니다.

--invocation-type Event|RequestResponse|DryRun; --log-type Tail; --cli-binary-format

aws lambda invoke --function-name my-fn --payload '{"key":"value"}' out.json && cat out.json

DynamoDB

aws dynamodb scan --table-name <name>

DynamoDB 테이블을 스캔합니다 — 모든 항목을 읽습니다(가능하면 키 조건으로 `query`를 사용하세요).

--table-name; --filter-expression; --projection-expression; --select; --max-items

aws dynamodb scan --table-name users --max-items 5
aws dynamodb query --table-name <name> --key-condition-expression 'pk = :v' --expression-attribute-values '{":v":{"S":"u1"}}'

키 조건 표현식으로 파티션 키별 항목을 쿼리합니다.

aws dynamodb query --table-name users --key-condition-expression '#u = :u' --expression-attribute-names '{"#u":"userId"}' --expression-attribute-values '{":u":{"S":"u1"}}'

IAM

aws iam list-users

계정의 모든 IAM 사용자를 나열합니다.

--path-prefix /; --max-items

aws iam list-users --query 'Users[].UserName' --output text
aws iam create-user --user-name <name>

새 IAM 사용자를 만듭니다.

aws iam create-user --user-name new-dev
aws iam attach-user-policy --user-name <name> --policy-arn <arn>

관리형 정책을 사용자에게 연결합니다.

aws iam attach-user-policy --user-name new-dev --policy-arn arn:aws:iam::aws:policy/ReadOnlyAccess

프로파일

aws --profile <name> <service> <cmd>

명명된 프로파일(미리 설정되어 있어야 함) 하에서 모든 명령을 실행합니다.

--profile prod; --profile dev; --profile staging

aws --profile prod s3 ls
AWS_PROFILE=<name> aws <service> <cmd>

환경 변수로 프로파일을 설정합니다 — 스크립트에서 유용합니다.

AWS_PROFILE=prod aws lambda list-functions

진단

aws --debug <service> <cmd>

HTTP 와이어 레벨 로그를 stderr에 덤프합니다 — 서명 또는 페이로드 오류를 진단할 때 유용합니다.

--debug; --no-verify-ssl; --ca-bundle <file>; --cli-read-timeout <seconds>

aws --debug s3 ls 2> aws.log
aws --no-sign-request <service> <cmd>

서명되지 않은 요청을 만듭니다 — 공개 버킷 / 테스트 엔드포인트에 유용합니다.

aws --no-sign-request s3 cp public.txt s3://public-bucket/x

관련 명령어 치트시트

AWS CLI 소개

AWS Command Line Interface(awscli)는 터미널에서 AWS 서비스를 제어하기 위한 Amazon의 공식 도구입니다. 현재 라인은 AWS CLI v2(2020년 출시; awscli 1.x는 유지보수 모드)입니다. v2는 단일 설치 프로그램(msi / pkg / 서명된 zip)으로 제공되며, SSO, 새로운 `aws sso login` 흐름, 자동 페이징, 바이너리 매개변수(Lambda zip 업로드 같은 base64 인코딩 blob 처리)를 지원합니다. 설정은 `~/.aws/config`(region, output format)와 `~/.aws/credentials`(액세스 키)로 분리되지만, IAM Identity Center / SSO를 사용할 때는 보통 장기 키 대신 `aws sso configure`를 사용합니다. 모든 AWS 서비스는 `aws <service> <command>`로 접근할 수 있습니다 — `aws ec2 describe-instances`, `aws s3 sync`, `aws lambda call`, `aws dynamodb scan`. CLI는 Apache-2.0 라이선스입니다. 더 새로운 대안으로는 인터랙티브 완성을 위한 `aws-shell`과 인프라스트럭처-as-code용 AWS CDK(`cdk`)가 있습니다. AWS CLI v2는 명시적으로 호출한 API 호출 외에는 소스 코드를 업로드하지 않습니다.

치트시트 버전 1.0.0