Skip to content
Quest 04Beginner12 min

Get Your Starter Pokémon

Welcome to Professor Oak's lab! It's time to choose your first partner Pokémon. You have three options: Bulbasaur, Charmander, or Squirtle. Once you've made your choice, you'll need to fetch your starter from the Pokédex using DynamoDB. Unlike scanning the entire table, you can retrieve a specific Pokémon efficiently using its Name as the partition key.
Start the lesson

What you'll learn

  • GetItem retrieves a single item by its primary key efficiently.
  • Using the partition key directly is faster than scanning the entire table.
  • GetItem needs the full primary key: the partition key, plus the sort key if the table has one.

Section 01

The Choice

Professor Oak presents you with three starter Pokémon. Each has unique characteristics that will shape your journey. Take a look at their types and sizes:

NameType1Type2Height(m)Weight(kg)
Bulbasaurgrasspoison0.76.9
Charmanderfire---0.68.5
Squirtlewater---0.59.0

Choose wisely! Each starter has a different type and build that will influence your adventure.

Section 02

Why GetItem Instead of Scan?

In Quest 3, you learned about Scan, which reads every item in the table. But when you know exactly which Pokémon you want, there's a much more efficient way!

  • Scan reads through every single item in the table, even if you only need one Pokémon.
  • GetItem uses the partition key to go directly to the exact item you want, like looking up a word in a dictionary.
  • GetItem is faster and cheaper because DynamoDB doesn't need to examine every item.
  • You must know the exact Name value to use GetItem—perfect for fetching your chosen starter!
  • GetItem is eventually consistent by default (half a read unit per 4 KB). Add ConsistentRead: true when you must see the very latest write; it costs a full read unit.
Your appAWS SDK v3DynamoDBtableP0P1P2P3CONSUMED0

Ready · 7 steps · Sprig

This animation plays when you scroll to it. Press Play to start it now.

All steps as text
  1. Your app sends Scan to the Pokemon table. FilterExpression Name = "Bulbasaur"
  2. P0 reads 3 items to return 1: Bulbasaur.
  3. P1 reads 2 items to return 0.
  4. P2 reads 2 items to return 0.
  5. P3 reads 1 items to return 0.
  6. This call consumed 1 RCU.
  7. DynamoDB responds with success: 8 items read and paid for to find 1.

Section 03

Fetching Your Starter Pokémon

Now it's time to fetch your chosen starter. This is an authentic GetItem request shape evaluated only by the ServerlessCreed emulator:

Key Points: Notice how we specify the exact Name in the Key object. DynamoDB uses this to compute the hash and go directly to the partition containing that Pokémon. This is much more efficient than scanning the entire table!

GetItem command with AWS SDK v3TypeScript
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient, GetCommand } from "@aws-sdk/lib-dynamodb";

const client = new DynamoDBClient({
  region: "ap-south-1",
});
const docClient = DynamoDBDocumentClient.from(client);

async function getStarterPokemon(pokemonName: string) {
  const command = new GetCommand({
    TableName: "Pokemon",
    Key: {
      Name: pokemonName,
    },
  });

  try {
    const response = await docClient.send(command);
    
    if (response.Item) {
      console.log("Starter Pokémon found:", response.Item);
      return response.Item;
    } else {
      console.log("Pokémon not found");
      return null;
    }
  } catch (err) {
    console.error("GetItem failed:", err);
    throw err;
  }
}

getStarterPokemon("Bulbasaur");

Practice

Your turn

The example fetches Pikachu. Change the Name in the Key object to one of the starters — "Bulbasaur", "Charmander" or "Squirtle" — then press Run code. Stuck? The Reference solution tab has the answer.
Only the Name line inside Key is editable. Pick your starter.
Tab inserts two spaces. Press Escape, then Tab, to leave the editor. Control or Command plus Enter runs the code. Only line 15 can be edited.
Simulated — no AWS calls

Check

Check your understanding

Quick Quiz · one question, as many tries as you need.

When you know the exact Name of a Pokémon you want to fetch, which operation should you use?

Choose one answer.