Chrysolites Tech Academy

Cloud Certifications: AWS, Azure and Kubernetes · Course book

Chapter 2: Building on AWS

Pairs with Lesson 2: AWS Certified Developer Associate

The Cloud Practitioner exam asks what AWS services do. The Developer Associate exam asks how to build with them: how to store and query data efficiently, deploy applications safely, run code without servers, coordinate workflows, trace problems and automate releases. This chapter covers the services and ideas the exam concentrates on, with the calculations that commonly appear in its questions, such as working out database capacity and the cost of serverless functions.

Working with AWS as a developer

Developers reach AWS in three ways. The console is the website, good for exploring. The command-line interface, the AWS CLI, runs the same operations as typed commands, which makes them scriptable. And the SDKs, libraries for languages such as Python, JavaScript and Java, let application code call AWS directly, for example to upload a file to S3 or read an item from a database. All three use the same underlying API, and all three authenticate with credentials.

How those credentials are supplied matters a great deal. On a developer's computer they come from a local profile set up with the CLI. In AWS itself, code should never contain access keys. Instead, an EC2 instance, a Lambda function or a container is given an IAM role, and the SDK automatically obtains short-lived credentials from it. Exam questions often present tempting options that embed keys in code or configuration files; the correct answer is almost always a role.

Infrastructure for applications is usually described with CloudFormation templates, covered in the infrastructure-as-code course: a template lists resources, a stack is one deployment of it, and changes are previewed with change sets before being applied.

DynamoDB: capacity and access patterns

DynamoDB is AWS's fully managed key-value and document database, built for consistent speed at any scale. Every table has a primary key: either a partition key alone, or a partition key plus a sort key. The partition key decides which internal partition stores an item, so it should have many distinct values to spread the load evenly; a key such as "country" with a handful of values creates hot spots, while a user ID spreads well.

Reads come in two kinds. A query finds items by primary key and is efficient. A scan reads the whole table and filters afterwards, which is slow and costly on large tables. To query by something other than the primary key, you add a secondary index: a local secondary index shares the partition key but uses a different sort key, while a global secondary index can use entirely different keys.

In provisioned mode, you pay for throughput measured in capacity units, and exam questions frequently ask you to calculate them.

  • One read capacity unit, RCU, allows one strongly consistent read per second of an item up to 4 KB, or two eventually consistent reads of that size.
  • One write capacity unit, WCU, allows one write per second of an item up to 1 KB.
  • Item sizes are rounded up to the next 4 KB for reads and the next 1 KB for writes.

Suppose an application reads 10 items a second, each 6 KB. Rounded up, 6 KB counts as 8 KB, which is 2 units of 4 KB. Strongly consistent reads need 10 × 2 = 20 RCU; eventually consistent reads need half, 10 RCU. If it also writes 5 items a second of 2.5 KB, each rounds up to 3 KB, needing 5 × 3 = 15 WCU.

a 6 KB item needs 2 units 1234 0481216item size (KB) RCU per strongly consistent read each second
Figure 2.1 — Read capacity rises in steps, because item sizes are rounded up to the next 4 KB. A 4.1 KB item costs as much to read as an 8 KB one.

For unpredictable traffic, on-demand mode charges per request with no planning. DynamoDB Streams record every change to a table, which can trigger a Lambda function, and DAX adds an in-memory cache for microsecond reads. When requests exceed capacity, DynamoDB throttles them, and SDKs retry with exponential backoff, waiting longer after each failed attempt. Persistent throttling usually means either too little capacity overall or a poorly chosen partition key that sends most traffic to one partition, and the fix differs: more capacity for the first, a better key for the second.

Deploying applications

Elastic Beanstalk deploys web applications without building the infrastructure by hand: you upload code, choose a platform such as Node.js or Python, and it creates the servers, load balancer and scaling rules. Its deployment policies are a favourite exam topic.

PolicyHow it worksDowntimeRollback
All at onceUpdates every instance simultaneouslyYesRedeploy the old version
RollingUpdates instances in batchesNo, but capacity is reducedRedeploy
Rolling with additional batchAdds a fresh batch first, so capacity never dropsNoRedeploy
ImmutableLaunches a complete new set of instances, then swapsNoFast: terminate the new set

Beanstalk environments are configured through the console or through configuration files placed in a folder called .ebextensions in the application's source bundle, which can install packages, set environment variables and adjust settings on every instance. A common pattern keeps two environments, one serving users and one with the new version, and swaps their web addresses when the new one is ready, giving a blue/green deployment with an instant way back.

For containers, ECS runs Docker containers described by task definitions, which set the image, memory and processor, ports and the IAM role for the task. With the Fargate launch type, AWS supplies the servers; with the EC2 launch type, you manage a cluster of instances yourself. Images are stored in ECR, AWS's container registry.

Serverless and orchestration

Lambda runs functions in response to events, such as an API request through API Gateway, a file arriving in S3, a message on a queue or a change in a DynamoDB table. You choose the memory, from 128 MB upwards, and processor power scales with it; a single run can last up to 15 minutes. Billing is by the number of requests and by GB-seconds: memory in gigabytes multiplied by duration. A function with 512 MB running for 200 milliseconds, invoked a million times, uses 0.5 × 0.2 × 1,000,000 = 100,000 GB-seconds. Doubling memory can actually reduce cost if it makes the function finish more than twice as fast.

Two Lambda behaviours often appear in questions. A cold start happens when a function runs for the first time or after being idle: AWS must prepare a fresh environment, adding a delay, while later calls reuse it and start almost instantly. And settings such as database addresses belong in environment variables, with secrets stored in a service such as Secrets Manager or Parameter Store and fetched at run time, never written into the function's code.

Applications built from many functions need coordination. SQS, a message queue, lets one part hand work to another reliably, smoothing bursts of traffic. SNS broadcasts a message to many subscribers at once. Step Functions coordinate multi-step workflows as state machines, defined in JSON, with steps, choices, parallel branches, retries and error handling, so that the logic of a process such as "charge the card, then reserve stock, then send a confirmation" lives in one visible diagram instead of being scattered through code.

Finding problems in a distributed application is hard, because one request may pass through API Gateway, three functions and a database. X-Ray traces requests end to end: each service adds a segment recording its timing, and X-Ray assembles them into a service map and a timeline that shows exactly where a slow or failing request spent its time.

Exam habit. When a question says "with the least operational overhead", the answer is usually a managed or serverless service: Fargate over EC2, DynamoDB over a database on your own instance, Lambda over a server running a scheduled script.

Continuous delivery on AWS

AWS offers its own family of CI/CD services, each covering one stage.

CodePipeline: runs the stages in order on every change CodeCommitGit repositoriesCodeBuildbuild and test, buildspec.ymlCodeDeployto EC2, Lambda or ECS Each service can also be used on its own, alongside other tools.
Figure 2.2 — AWS's developer tools as one pipeline. Source, build and deploy are separate services, joined together by CodePipeline.

CodeCommit hosts Git repositories. CodeBuild runs builds and tests in temporary containers, following instructions in a buildspec.yml file. CodeDeploy deploys new versions to EC2 instances, Lambda functions or ECS services, guided by an appspec file, with strategies such as in-place updates or blue/green deployments and traffic shifted gradually for Lambda. CodePipeline connects the stages, starting a run automatically whenever code changes.

Check your understanding

  • Why should code running on AWS use an IAM role instead of access keys?
  • What is the difference between a DynamoDB query and a scan?
  • How many RCU are needed for 20 strongly consistent reads a second of 3 KB items? (Answer: 3 KB rounds up to 4 KB, 1 unit each, so 20 RCU.)
  • How many WCU are needed for 4 writes a second of 1.5 KB items? (Answer: 1.5 KB rounds up to 2, so 8 WCU.)
  • Which Elastic Beanstalk policy keeps full capacity and gives the fastest rollback? (Answer: immutable.)
  • A function with 1 GB of memory runs for 300 milliseconds, 500,000 times. How many GB-seconds is that? (Answer: 1 × 0.3 × 500,000 = 150,000.)
  • What problem does X-Ray solve, and what is a Step Functions state machine?

Install Chrysolites Tech Academy

Android / Chrome / Edge: open the browser menu and choose Install app or Add to Home screen.

iPhone / iPad (Safari): tap the Share button, then Add to Home Screen.