In this blog post, I’ll discuss how to work on multiple projects which require different credentials by using the profile functionality in the Amazon Alexa Skills Kit Command Line Interface (ASK CLI).
I’m new to the Alexa team and as I started setting up my development environment with the ASK CLI, I had a question about the best way to do it. The ASK CLI needs credentials to run many commands. But how do you make sure it uses the right ones?
I have an Amazon developer account associated with my personal email address, one associated with my Amazon work address, and it’s possible I might have to use identities for team or organizational accounts. I realized that developers who work for multiple clients or on projects with separate Amazon Web Services or Amazon Developer team accounts could have the same problem.
The Solution: Profiles
A profile is a developer identity stored in your ASK CLI configuration, containing information about which Amazon developer account and AWS IAM user account should be used when executing commands. You can have multiple profiles with different names to specify which credentials to use when running a command.
How to Create a Profile
Running `ask init` from the command line for the first time will start a wizard to help you set up your default profile, but don’t do that yet. I’ll talk a little later in this post about whether a default profile is your best option.
To set up a named profile, use `ask init –p [name]`, where “[name]” is the name you want to use for the profile.
After you have set up any profile, when you run the setup wizard, it will ask you to select an existing profile to modify or provide a name for the new profile. Using `ask init –p [name]` will skip the selection/naming step.
Use Your Shiny New Profile
On any ASK CLI commands you want to run with a named profile, add `–p [name]` to execute those commands with that profile.
Now you can work on multiple projects with different sets of credentials more easily.
Should You Create a Default Profile?
Let’s look at some pros and cons around the default profile.
Having a default profile:
- Pro: Commands always have a set of credentials to use.
- Con: If you need to use a named profile’s credentials, but forget to specify it, the default profile’s credentials will be used. The command runs, but that could create a mess, because it used the default profile’s accounts, not the ones you intended.
Not having a default profile:
- Pro: You’re less likely to run commands using the wrong credentials.
- Con: When you don’t have a default profile and forget to specify a named profile, the command will fail and you have to re-run it with a named profile. This may seem like a good failsafe, but it could become annoying.
A Session-Limited Default Is the Best of Both Worlds
If you’re going to work on one project for a while, you can set a session-limited default from your command line by setting the `ASK_DEFAULT_PROFILE` environment variable with the name of the profile you want to use. Here’s how to do that:
[Windows Command Prompt] set ASK_DEFAULT_PROFILE=[profile name] [Linux / BSD / Mac] export ASK_DEFAULT PROFILE=[profile name]
The ASK CLI, when run in the terminal where you set the variable, will use that specified profile as the default until you close the terminal session.
Thanks for reading this post on using profiles with the Alexa Skills Kit Command Line Interface (ASK CLI). Do you have a tip or trick of your own for managing multiple accounts? Share them with me on Twitter at @YiddishNinja.
Source: Alexa Developer Blog