In this section, you will create an Amazon Cognito User Pool. As part of this process, you will note the details that you need in order to complete the Account Linking details section when creating the Alexa skill.
- Login to the AWS Console and navigate to the Cognito service. Click here to go directly there.
- Check the AWS region being used by looking in the upper right of the console. Change it if desired.
You can use any region supported by Cognito, however we recommend that you use one of the four regions that supports the Alexa Skills trigger so you can keep all the related resources in the same region. Those four regions are us-east-1 (N. Virginia), us-west-2 (Oregon), eu-west-1 (Ireland) and ap-northeast-1 (Tokyo). If necessary, switch to your desired region.
- Click Manage User Pools.
- Click Create a user pool.
For the purposes of this sample, only the minimum required settings are being changed. For production use, be sure to review each section and update accordingly.
- Enter a Pool name, such as
Alexa Skill Users
and click Review Defaults. - Select Attributes on the left-side menu.
- Select Email address or phone number and choose Allow email addresses.
- In the Which standard attributes do you want to require? section, check the following:
- address
- family name
- given name
- phone number
- Click Next Step.
- Select MFA and verifications on the left-side menu and set:
- Do you want to enable Multi-Factor Authentication (MFA) to Off
- Which attributes do you want to verify? to Email
- Click Save Changes.
- Select App clients on the left-side menu, then click Add an app client.
- Enter an App client name such as
AlexaDemoSkill
. - Enter
3650
in the Refresh token expiration (days) field.For Alexa account linking, it is best practice to have refresh tokens that do not expire. Amazon Cognito allows a maximum expiry time of 3650 days (10 years), so we will use that maximum.
- Ensure that the Generate client secret box is checked. (The remaining boxes should be un-checked.)
- Click Create App Client.
- Select Review on the left-side menu and click Create pool at the base of the page. Once created, you will be presented with a message saying Your user pool was created successfully.
- Copy the Pool Id to your Scratch-Pad.
This is only needed if you will be using the CLI to create your test user.
- The left-sde menu will have changed. Select General settings >> App clients on the left-side menu, and select Show Details.
- Copy the App client id and App client secret to your Scratch-Pad.
- Select App integration >> App client settings on the left-side menu. Under Enabled Identity Providers, check the box next to Cognito User Pool.
- Next, construct the Callback URL list.
- In a scratch space (like your Scratch-Pad), replace the placeholder value
<VID>
in these URL's with your vendor Id (which you should find in your Scratch-Pad):https://alexa.amazon.co.jp/api/skill/link/<VID> https://layla.amazon.com/api/skill/link/<VID> https://pitangui.amazon.com/api/skill/link/<VID>
Note: These three URL’s correspond to the three Alexa regions: FE (co.jp), EU (layla) & NA (pitangui).
- Combine them into a single comma-separated value. For example, if your Vendor Id is M12AB34CD56EF7, the result would be:
https://alexa.amazon.co.jp/api/skill/link/M12AB34CD56EF7,https://layla.amazon.com/api/skill/link/M12AB34CD56EF7,https://pitangui.amazon.com/api/skill/link/M12AB34CD56EF7
- In a scratch space (like your Scratch-Pad), replace the placeholder value
- Copy/paste ths comma-separated Callback URL list into the Callback URL(s) field.
- Further down the same page, under OAuth 2.0 and Allowed OAuth Flows, check the box titled Authorization code grant.
- Under Allowed OAuth Scopes, check these boxes:
- openid
The openid scope returns all user attributes in the ID token that are readable by the client. The ID token is not returned if the openid scope is not requested by the client.
- aws.cognito.signin.user.admin
The aws.cognito.signin.user.admin scope grants access to Amazon Cognito User Pool API operations that require access tokens.
- profile
The profile scope grants access to all user attributes that are readable by the client. Note: phone and email are included in the profile scope so no need to tick these boxes.
- Click Save changes.
There are two options for setting your Cognito OAuth domain:
- Use a Cognito Domain. This option can only be used for trial and demonstration purposes.
- Use your own domain. This option is required if you intend to publish a skill that makes use of this Cognito pool.
Note: You need to own the OAuth domain if you wish to publish a skill (or skills) that uses this OAuth system.
Since you're just trying this out, you can use a Cognito domain.
- Select App integration >> Domain name from the left-side menu.
- Chose a domain prefix (e.g. myoauth) and enter it into the Domain Prefix field.
Note: The domain prefix has to be unique in the chosen AWS region.
- Click Check availability.
- If the domain prefix is not available, pick a new one and repeat the checking process.
- Once you have found an available domain prefix, click Save changes.
- Select App integration from the left-side menu.
- Copy the full URL (e.g. https://myoauth.auth.us-west-2.amazoncognito.com) shown in the Domain field to your Scratch-Pad.
If you are unsure about the management of SSL certificates for your domain, contact your network administrator. This sample assumes you have a domain managed by Amazon Route 53. Domains managed elsewhere may have different steps, which are outside the scope of this sample.
- Select App integration >> Domain name from the left-side menu.
- Click Use your domain. If you don’t have any existing managed certificates, then you will see the message We didn't find any AWS managed certificates for this region. To add one, click here.
- Click click here to start the Amazon Certificate Manager (ACM) creation process.
- Verify you are in the us-east-1 region for this step. If not, switch to it.
- On the Certificates Manager console, click Request a certificate.
- Select Request a public certificate.
- Click the Request a certificate button.
- Enter your domain name in the Domain name entry field, such as
auth.mydomain.com
and click Next. - Select DNS validation and click Review.
If you don't have the necessary permissions to use this method, choose Email validation instead.
- On the next screen, click Confirm and request.
- Click Continue.
Add a CNAME to your domain using the details provided. This process will vary depending o the domain hosting provider (eg, Route 53) which you are using. For Route 53 hosted zones, continue with this section.
- Expand the Domain entry for the domain you created and is pending validation. Click Create record in Route 53.
- Review the details and then click Create.
It can take 30 minutes or longer for the changes to propagate and for AWS to validate the domain and issue the certificate.
- Once the certificate is validated, return to the Cognito console and the region in which you created your User Pool.
- Enter the Domain Name and select the AWS Managed Certificate.
- Click Save Changes.
- Copy the Alias Target to your Scratch-Pad.
- Create the alias record in Route53.
- Navigate to the Route53 console.
- Click on Hosted zones.
- Click on your domain.
- Click on Create Record Set.
- Enter the subdomain into the Name field.
- Set the type to A - IPv4 address.
- Set Alias to Yes.
- Paste the Alias Target from your Scratch-Pad to the Alias Target field.
- Click Create.
- Return to the Cognito console.
- Select App integration from the left-side menu.
- Copy the full URL (e.g. https://auth.mydomain.com) shown in the Domain field to your Scratch-Pad.
Congrats! You've created your User Pool and are ready to move on to the next step of creating the AWS IAM role which will be used by the AWS Lambda function that backs your skill.
To continue using the AWS Console, click here. If you'd prefer to switch to the CLI, click here.