- Amazon Developer Portal Account
- Amazon Web Services Account
- ASK NodeJS SDK
- ASK CLI
- AWS CLI
- A basic understanding of Node.js and TypeScript
This code sample will update your catalogs and skill with the use of ASK NodeJS SDK. Developers will need to provide their own client id, client secret, and refresh token.
- Obtain LWA client ID and client secret.
- Generate refresh token using ask cli. (You can specify
alexa::ask:skills:readwrite
with --scopes or not use --scopes.) - Input obtained ids and token to
index.js
. - Replace sample catalogId and URL with your values. You can update more than one catalog.
- Input skill id to update in
index.js
- Run
node index.js
from package root to update catalog and skill. - Follow steps below to run update periodically
- Set up your CDK project
npm install -g aws-cdk
cdk init app --language=typescript
- Install AWS SDK if not already installed
npm install aws-sdk
- Add the necessary imports in lib/{AnyStackName}.ts:
import * as cdk from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as events from 'aws-cdk-lib/aws-events';
import * as targets from 'aws-cdk-lib/aws-events-targets';
- Create the AWS Lambda function and configuration to run on schedule using AWS Event Bridge. Modify the cron function to configure how often to update
export class YourStackNameStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// Define the Lambda function
const lambdaFunction = new lambda.Function(this, 'YourLambdaFunction', {
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'index.handler',
code: lambda.Code.fromAsset("PATH_TO_ASK_AUTOMATIC_CATALOG_UPDATE_FUNCTION"),
});
// Create an EventBridge rule to trigger the Lambda function every hour
const rule = new events.Rule(this, 'YourRule', {
schedule: events.Schedule.cron({ hour: '0' }),
});
// Add the Lambda function as the target of the EventBridge rule
rule.addTarget(new targets.LambdaFunction(lambdaFunction));
}
}
- Build project using
npm run build
- Deploy stack using
cdk deploy
Note: This can be done without AWS CDK. Simply zip up node package and configure AWS lambda/Eventbrige via AWS console
Modify the runInteractionModelUpdateWorkflow
function in index.js
to the following to submit skill for instant publish.
Note: Skill will not instant publish if there are changes other than catalog values.
async function runInteractionModelUpdateWorkflow() {
try {
await createDirectories();
await createInteractionModelCatalogVersion();
await getSkillPackageAndUpdateCatalogVersion();
await submitSkillForCertification();
} catch (error) {
console.error('Error when running update workflow', error);
throw new Error('Workflow failed', {cause: error});
}
}