Working from Code: AWS CLI, SDKs and CloudShell
The console is great for learning, but real work is automated. Everything you click in the console is an API call – and the AWS CLI and SDKs let you make those calls from a terminal or your own code.
The AWS CLI
aws configure # access key, secret, default region, output format
aws sts get-caller-identity # who am I?
aws ec2 describe-instances --region ap-south-1
aws s3 ls s3://my-bucket
aws s3 cp report.pdf s3://my-bucket/reports/
aws lambda invoke --function-name hello --payload '{"name":"Asha"}' \
--cli-binary-format raw-in-base64-out out.json
| Feature | Example |
|---|---|
| Command structure | aws <service> <operation> --parameters |
| Profiles | aws s3 ls --profile prod (from ~/.aws/credentials) |
| Output formats | `--output json |
| Filtering with JMESPath | --query "Reservations[].Instances[].InstanceId" |
| Pagination | --max-items, --starting-token |
| Dry run | aws ec2 run-instances … --dry-run (checks permissions) |
CloudShell
AWS CloudShell is a browser-based shell already signed in with your console identity, with the CLI, Python, Node.js, git and jq pre-installed and 1 GB of persistent home storage. No keys to manage – ideal for quick tasks and labs.
Where credentials come from (provider chain)
- Environment variables (
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_SESSION_TOKEN) - Shared files
~/.aws/credentialsand~/.aws/config(profiles, SSO) - Container / instance role – ECS task role, EC2 instance profile, Lambda execution role
Code running on AWS should never contain keys – it receives temporary credentials from its role automatically through this chain.
The SDKs
AWS provides SDKs for JavaScript/TypeScript, Python (boto3), Java, .NET, Go and more.
JavaScript SDK v3 is modular: one package per service, a client and command objects.
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { DynamoDBDocumentClient, PutCommand } from '@aws-sdk/lib-dynamodb';
const db = DynamoDBDocumentClient.from(new DynamoDBClient({ region: 'ap-south-1' }));
await db.send(new PutCommand({ TableName: 'Products', Item: { id: 'p1', name: 'Mouse' } }));
Python (boto3):
import boto3
s3 = boto3.client("s3")
for obj in s3.list_objects_v2(Bucket="my-bucket").get("Contents", []):
print(obj["Key"], obj["Size"])
| SDK concept | Meaning |
|---|---|
| Client | Connection to one service in one Region |
| Command / operation | One API call (PutCommand, put_object) |
| Retries & backoff | Built in for throttling and transient errors |
| Errors | Typed exceptions – AccessDeniedException, ResourceNotFoundException, ConditionalCheckFailedException |
| Waiters / paginators | Helpers to wait for a state or iterate through pages |
Infrastructure as code vs scripts
CLI scripts are fine for one-off tasks; for repeatable environments use CloudFormation, CDK or Terraform (Module 7).
Practise it
Virtual lab · Amazon Web Services · 20 min
Automate AWS with the CLI in CloudShell
Use the AWS CLI from CloudShell to inspect your identity, list resources as JSON and create networking with commands – the foundation of infrastructure automation.
Quick revision
aws <service> <operation>; use profiles,--outputand--query.- CloudShell = pre-authenticated browser terminal.
- Credentials chain: env vars → config files → role.
- SDK v3: client + command +
send(). - Never hard-code keys; use roles.
Practise this topic
Hands-on virtual lab
Apply what you just read in a realistic, guided simulation. Free with a verified account.
Create a free account to track your progress and unlock virtual labs.