Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • AI
    • Cloud
Google Cloud Platform icon
Labs

Using Session Attributes in an Alexa Skill

In this lab, you will store session attributes on the launch request to be used in the final response. Objectives for this lab include creating and setting session attributes, getting session attributes in a later intent, using the session attributes in the response, and deploying and testing the skill. **Note:** You must have your own Amazon Developer account, which you can [sign up](https://developer.amazon.com/) for if you do not already have one.

Google Cloud Platform icon
Lab platform
Lab Info
Level
Beginner
Last updated
May 13, 2025
Duration
30m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Configure Amazon Skills Kit to Use Your AWS Developer Account
    1. Initialize the ASK CLI:

      ask init --no-browser
      
    2. Copy/paste the URL that appears from the terminal to a browser window.

    3. Log in to the developer console when prompted.

    4. Copy/paste the authorization code.

    5. Enter y for Yes to connect to the AWS account already set up on the VM.

    6. Choose the default AWS account.

  2. Challenge

    Clone and Check Out Branch
    1. Clone the template skill:

      ask new --url https://github.com/linuxacademy/content-aws-skill-builder.git
      
    2. Navigate into the directory:

      cd content-aws-skill-builder
      
    3. To start with a template and perform the tasks for this lab yourself:

    git checkout lab_attributes
    
    1. To start with the solution to the lab:

      git checkout lab_attributes_solution
      
  3. Challenge

    Develop the Skill

    In ../lambda/custom/index.js:

    1. Add session attributes to LaunchRequest:

        const LaunchRequestHandler = {
            canHandle(handlerInput) {
                return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
            },
            handle(handlerInput) {
                const vets = { "dog": "Dr. Kay Nine", "cat": "Dr. Fee Line" }
                handlerInput.attributesManager.setSessionAttributes(vets);
      
                const speakOutput = "Exclusive Veterinary Services welcomes you. You can say I want to register my pet.";
      
                return handlerInput.responseBuilder
                    .speak(speakOutput)
                    .reprompt(speakOutput)
                    .withSimpleCard('Exclusive Vet Services', 'We are here for your fur-baby.')
                    .getResponse();
            }
        };
      
    2. Get session attributes and use in the response in CompletedRegisterPetIntentHandler:

        const CompletedRegisterPetIntentHandler = {
            canHandle(handlerInput) {
                const request = handlerInput.requestEnvelope.request;
      
              return request.type === 'IntentRequest'
                && request.intent.name === 'RegisterPetIntent'
                && request.dialogState === 'COMPLETED';
            },
            handle(handlerInput) {
      
                // Session attributes
                const vets = handlerInput.attributesManager.getSessionAttributes();
                console.log('have vets')
                // Slot values
                pet_type = handlerInput.requestEnvelope.request.intent.slots.pet_type.resolutions.resolutionsPerAuthority[0].values[0].value.name
                pet_name = handlerInput.requestEnvelope.request.intent.slots.pet_name.value
                pet_breed = handlerInput.requestEnvelope.request.intent.slots.pet_type.value
                console.log('ready for output')
                const speechOutput1 = "We are happy to welcome your " + pet_breed + ". Your " + pet_type + " named " + pet_name + " is registered! ";
                const speechOutput2 = pet_name + "'s veterinarian is " + (pet_type === "dog" ? vets.dog : vets.cat) + ".";
                const speakOutput = speechOutput1 + speechOutput2
      
                return handlerInput.responseBuilder
                    .speak(speakOutput)
                    //.reprompt('add a reprompt if you want to keep the session open for the user to respond')
                    .getResponse();
            }
        };
      
  4. Challenge

    Deploy and Test
    1. Deploy the skill:

      ask deploy
      
    2. Begin performing a test:

      ask dialog --locale en-US
      
    3. The prompt will change to User >.

    4. Enter open exclusive vet and follow the prompts.

  5. Challenge

    Cleanup Amazon Developer Account Alexa Console

    At this point the skill you just created should be deleted from your Alexa Console.

    Please do so at this link Alexa Console.

About the author

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight