KKeySync
← Back to quests

Quest · quest 4

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.

GetItemPrimary-key lookupRead consistency

Key takeaways

  • GetItem retrieves a single item by its primary key efficiently.
  • Using the partition key directly is faster than scanning the entire table.
  • GetItem requires knowing the exact key value you want to fetch.

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 stats:

Remember: In Quest 2, we built a table with Name as the partition key. This means we can fetch any Pokémon directly by name!
NameType1Type2Height(m)Weight(kg)
Bulbasaurgrasspoison0.76.9
Charmanderfire---0.68.5
Squirtlewater---0.59.0

Choose wisely! Each starter has different types and stats that will influence your adventure.

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!

Fetching Your Starter Pokémon

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

Key Points: Notice how we specify the exactName 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

Interactive Challenge

The example shows a GetItem operation fetching Pikachu. Your task is to modify the Name in the Key object to fetch one of the starter Pokémon: "Bulbasaur", "Charmander", or "Squirtle". Write your code in the editor below, then check the Solution tab to verify your answer.

Your CodeTypeScript

Quick Quiz

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

Make your choice to test your understanding. Submit to check, and if it's not quite right you can adjust and try again.