Interacting with AWS

Everything is an API call: the Console, CLI, SDKs, and infrastructure as code with CloudFormation.

What is it?

Every action in AWS (launching a server, creating a bucket, changing a permission) is an API request: an authenticated HTTPS call. Each way of using AWS is just a different front end to the same APIs.

  • AWS Management Console: the browser interface. Good for learning, exploring and one-off checks.
  • AWS CLI: a command-line tool for scripts and quick automation.
  • SDKs: libraries for languages such as JavaScript, Python, Java and Go, to call AWS from your app.
  • Infrastructure as code (IaC): describe resources in a file and let a tool create them. AWS CloudFormation uses JSON or YAML templates. A template becomes a stack you create, update and delete as one unit.

Two higher-level options save you work. AWS Elastic Beanstalk takes your app code and sets up and manages the environment (servers, load balancing, scaling), while you keep control of the underlying resources. The AWS CDK lets you write IaC in a normal programming language; it turns into CloudFormation.

One-time vs repeatable actions: use the Console for exploring and one-off tasks, where clicking is fast. Use the CLI, SDKs or CloudFormation when a task must be repeated, scripted or reviewed. The same command or template gives the same result every time and can live in version control.

Connecting to AWS has three network paths:

  • Public internet: cheapest and quickest to set up, but performance varies.
  • AWS Site-to-Site VPN (and Client VPN for individual users): encrypted traffic over the internet to a VPC.
  • AWS Direct Connect: a dedicated private connection from your site to AWS with steady bandwidth and latency. It takes time to set up and is not encrypted by default.
  • Many organisations use Direct Connect for steady traffic with a VPN as backup.

Getting around the Management Console

  • The search bar is the fastest way to open a service. Some consoles are umbrella consoles: security groups, EBS volumes, load balancers and Auto Scaling all live inside the EC2 console.
  • The Region selector (top right) controls what you see for Regional services. A resource made in one Region is hidden when another Region is selected: the classic "my server disappeared" moment. Global services such as IAM, Route 53 and CloudFront show Global instead.
  • Regions launched since 2019 are disabled by default. Enable (opt in to) them in account settings first.
  • Console screens change often, so tutorial screenshots may not match.

Under the hood: each service has endpoints. Regional ones include the Region code; global services use a global endpoint. Every request is signed with Signature Version 4 using an access key ID and secret access key. It names an action such as DescribeInstances or ListBuckets, the same action names used in IAM policies. Tools do the signing for you, so you rarely call the raw API. Some names are historical: VPC operations, for example, belong to the EC2 API.

Account IDs and ARNs

  • Every AWS account has a unique 12-digit account ID. It shows up in IAM sign-in URLs (or set a friendlier account alias), cross-account role trust, policy conditions, ARNs and support cases. It is not a secret, but avoid publishing it.
  • An Amazon Resource Name (ARN) uniquely identifies a resource: arn:partition:service:region:account-id:resource. The partition is aws for standard Regions, aws-cn for China and aws-us-gov for GovCloud.
  • S3 bucket ARNs leave Region and account blank (arn:aws:s3:::my-bucket) because bucket names are globally unique. IAM policies can use the * wildcard in ARNs.

The AWS CLI in practice

  • The program is aws and runs on Windows, macOS and Linux. Version 2 is current and bundles everything it needs (no separate Python install).
  • aws configure asks for an access key ID, secret access key, default Region and output format (json, table, text).
  • Credentials live in ~/.aws/credentials and settings in ~/.aws/config. Keep several named profiles and pick one with --profile; otherwise the default profile is used.
  • aws s3 has high-level commands (ls, cp, sync, mb). aws s3api exposes each low-level S3 API operation.

SDKs exist for Python, JavaScript/Node.js, Java, Go, .NET, Ruby, PHP, C++ and more. Create a client for a service, then call its operations. SDKs find credentials on their own, from environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN), the shared credentials file, or an attached IAM role. Never hard-code keys.

AWS CloudShell is a browser shell opened from the console. It is already signed in as you and has the AWS CLI, Python, Node.js, git and more. It offers bash, zsh and PowerShell, keeps a small home directory per Region between sessions, and costs nothing extra. It replaces AWS Cloud9, which is closed to new customers.

AWS Tools for PowerShell let Windows admins call AWS with Verb-Noun cmdlets (for example New-S3Bucket) that work with objects, not plain text.

Explain like I'm 10

A restaurant has one kitchen but several ways to order: tell a waiter (Console), fill in a paper slip (CLI), or let an app order for you (SDK). Infrastructure as code is handing the kitchen a written recipe for the whole banquet, so you get the same banquet every time.

Examples

The same action, three ways

# 1) Console: click S3 -> Create bucket.
# 2) CLI:
aws s3 mb s3://zykit-demo-bucket-12345 --region eu-west-1

# 3) Raw API under the hood (the CLI signs and sends this for you):
#    PUT https://zykit-demo-bucket-12345.s3.eu-west-1.amazonaws.com/
#    Authorization: AWS4-HMAC-SHA256 ...

Bucket names are globally unique, so change the number. All three paths end at the same API.

A CloudFormation template (YAML)

AWSTemplateFormatVersion: "2010-09-09"
Description: A versioned, private S3 bucket
Parameters:
  BucketName:
    Type: String
Resources:
  AppBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Ref BucketName
      VersioningConfiguration:
        Status: Enabled
      PublicAccessBlockConfiguration:
        BlockPublicAcls: true
        BlockPublicPolicy: true
        IgnorePublicAcls: true
        RestrictPublicBuckets: true
Outputs:
  BucketArn:
    Value: !GetAtt AppBucket.Arn

Declare the end state; CloudFormation works out the steps. Deleting the stack removes the bucket (if empty).

Deploying the stack

aws cloudformation deploy \
  --template-file bucket.yaml \
  --stack-name demo-bucket \
  --parameter-overrides BucketName=zykit-demo-bucket-12345

aws cloudformation describe-stacks --stack-name demo-bucket \
  --query "Stacks[0].Outputs"

aws cloudformation delete-stack --stack-name demo-bucket

How it works

Each request carries credentials and is cryptographically signed. AWS checks identity and permissions, then runs the action in the target Region. The Console, CLI and SDKs sign for you.

With CloudFormation you submit a template. The service works out the dependencies, creates resources in a safe order, and tracks them as a stack. A change set previews what an update would change before you apply it. If creation fails, the stack rolls back so nothing is left half-built.

  Console --+
  CLI ------+--> signed HTTPS --> AWS API --> resource
  SDK ------+                       ^
                                    |
  CloudFormation template --> stack-+
  (YAML/JSON, version-controlled)

Why does it exist?

Clicking through a console does not scale and cannot be reviewed, repeated or rolled back. Scripts and templates make environments repeatable, trackable in version control, and fast to rebuild after mistakes or disasters.

When to use it

Use the Console to learn and inspect. Use the CLI for quick automation. Use SDKs when your app must call AWS. Use CloudFormation (or CDK) for anything you will need again, like staging and production environments or shared team infrastructure. Use Elastic Beanstalk to deploy a web app quickly without designing the infrastructure.

When not to use it

Do not build production infrastructure only by hand in the Console; nobody can reproduce it later. Skip Elastic Beanstalk when you need fine control over every part; combine the services directly instead.

Common mistakes

  • Changing resources by hand that a CloudFormation stack manages, causing drift between the template and reality.

  • Committing access keys to a Git repository; prefer roles and short-lived credentials.

  • Running CLI commands against the wrong profile or Region.

  • Putting secrets in plain-text template parameters.

  • Skipping change sets and being surprised when an update replaces a resource (and its data).

  • Assuming Direct Connect is encrypted by default - add a VPN or MACsec if you need encryption.

  • Building production environments by clicking in the console, which cannot be repeated or reviewed.

  • Trying to use a newer Region without enabling it first in account settings.

  • Hard-coding access keys in application code instead of letting the SDK pick up a role or environment variables.

  • Publishing your account ID freely - it is not a password, but it helps attackers target you.

  • Forgetting --profile and running a command in the wrong account.

Practice exercises

  1. Easy:

    Create an S3 bucket with the CLI, list it, then delete it. Note which Region it landed in.

  2. Medium:

    Extend the YAML template to add a lifecycle rule. Validate it with aws cloudformation validate-template.

  3. Medium:

    Convert the example template to JSON using the YAML/JSON converter tool and compare the readability.

  4. Easy:

    Open CloudShell, run aws sts get-caller-identity, and find your 12-digit account ID in the output.

  5. Medium:

    Break this ARN into its parts and name each: arn:aws:iam::123456789012:user/asha. Why is the Region empty?

  6. Medium:

    Set up two CLI profiles (for example dev and prod) and show how to run the same command against each.

  7. Hard:

    How would you detect and fix configuration drift on a stack? What would you do if a teammate edited a resource by hand?

Interview questions

What do the Console, CLI, and SDKs have in common?

All of them send authenticated, signed requests to the same underlying AWS APIs.

What is infrastructure as code and why use it?

Describing infrastructure in files that a tool builds for you. Environments become repeatable, reviewable, version-controlled and quick to rebuild.

What is a CloudFormation stack?

The set of resources created from a template, managed together as a single unit for create, update, and delete.

Exam-style: Which service helps a developer deploy a web application without manually provisioning servers and load balancers, while still being able to access the underlying resources?

AWS Elastic Beanstalk.

Exam-style: Which service provisions AWS resources from a JSON or YAML template?

AWS CloudFormation.

Exam-style: Which option gives a dedicated private connection between an on-premises data center and AWS?

AWS Direct Connect.

When should you prefer infrastructure as code over the console?

When actions must be repeatable, reviewable and consistent, such as creating identical environments.

Exam-style: Which browser-based shell is pre-authenticated with your console credentials and has the AWS CLI preinstalled? (A) AWS Cloud9 (B) AWS CloudShell (C) Systems Manager (D) AWS CLI v1

B. AWS CloudShell.

What uniquely identifies any AWS resource?

Its Amazon Resource Name (ARN), in the form arn:partition:service:region:account-id:resource.

Where does the AWS CLI store credentials and default settings?

In ~/.aws/credentials and ~/.aws/config, organised by named profiles.

Why might you not see an EC2 instance you just created in the console?

The Region selector is set to a different Region; EC2 is a Regional service.

How do SDKs get credentials without hard-coding?

Through the default credential chain: environment variables, the shared credentials/config files, or an IAM role attached to the compute resource.