Skip to content
VirtualLP Virtual Learning Platform

Working from Code: AWS CLI, SDKs and CloudShell

12 min read Topic 4 of 30 1 hands-on lab

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)

  1. Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN)
  2. Shared files ~/.aws/credentials and ~/.aws/config (profiles, SSO)
  3. Container / instance role – ECS task role, EC2 instance profile, Lambda execution role
Key point

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.

Open lab

Quick revision

  1. aws <service> <operation>; use profiles, --output and --query.
  2. CloudShell = pre-authenticated browser terminal.
  3. Credentials chain: env vars → config files → role.
  4. SDK v3: client + command + send().
  5. 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.