Skip to content

Commit ec149fa

Browse files
author
Jay Krishnasamy
committed
initial commit of script
1 parent 0a9b96c commit ec149fa

File tree

4 files changed

+418
-9
lines changed

4 files changed

+418
-9
lines changed

README.md

Lines changed: 90 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,98 @@
1-
## My Project
1+
Automatically update your catalogs and skill
2+
=============
23

3-
TODO: Fill this README out!
4+
![Tutorial Header](https://m.media-amazon.com/images/G/01/mobile-apps/dex/alexa/alexa-skills-kit/tutorials/fact/header._TTH_.png)
45

5-
Be sure to:
66

7-
* Change the title in this README
8-
* Edit your repository description on GitHub
7+
## What You Will Need
8+
* [Amazon Developer Portal Account](http://developer.amazon.com)
9+
* [Amazon Web Services Account](http://aws.amazon.com/)
10+
* [ASK NodeJS SDK](https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs)
11+
* [ASK CLI](https://developer.amazon.com/en-US/docs/alexa/smapi/quick-start-alexa-skills-kit-command-line-interface.html)
12+
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)
13+
* A basic understanding of Node.js and TypeScript
914

10-
## Security
15+
## What this code sample will do
16+
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.
1117

12-
See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.
18+
## Instructions
19+
1. [Obtain LWA client ID and client secret](https://developer.amazon.com/en-US/docs/alexa/smapi/get-access-token-smapi.html#configure-lwa-security-profile).
20+
2. [Generate refresh token using ask cli](https://developer.amazon.com/en-US/docs/alexa/smapi/ask-cli-command-reference.html#generate-lwa-tokens).
21+
3. Input obtained ids and token to `index.js`.
22+
4. Replace sample catalogId and URL with your values. You can update more than one catalog.
23+
5. Input skill id to update in `index.js`
24+
6. Run `node index.js` from package root to update catalog and skill.
25+
7. Follow steps below to run update periodically
1326

14-
## License
27+
### Running script in AWS lambda
28+
1. Set up your CDK project
1529

16-
This library is licensed under the Amazon Software License.
30+
```
31+
npm install -g aws-cdk
32+
cdk init app --language=typescript
33+
```
1734

35+
2. Install AWS SDK if not already installed
36+
37+
```
38+
npm install aws-sdk
39+
```
40+
41+
3. Add the necessary imports in lib/{AnyStackName}.ts:
42+
43+
```
44+
import * as cdk from 'aws-cdk-lib';
45+
import * as lambda from 'aws-cdk-lib/aws-lambda';
46+
import * as events from 'aws-cdk-lib/aws-events';
47+
import * as targets from 'aws-cdk-lib/aws-events-targets';
48+
```
49+
50+
4. 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
51+
52+
```
53+
export class YourStackNameStack extends cdk.Stack {
54+
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
55+
super(scope, id, props);
56+
57+
// Define the Lambda function
58+
const lambdaFunction = new lambda.Function(this, 'YourLambdaFunction', {
59+
runtime: lambda.Runtime.NODEJS_14_X,
60+
handler: 'index.handler',
61+
code: lambda.Code.fromAsset("PATH_TO_ASK_AUTOMATIC_CATALOG_UPDATE_FUNCTION"),
62+
});
63+
64+
// Create an EventBridge rule to trigger the Lambda function every hour
65+
const rule = new events.Rule(this, 'YourRule', {
66+
schedule: events.Schedule.cron({ hour: '0' }),
67+
});
68+
69+
// Add the Lambda function as the target of the EventBridge rule
70+
rule.addTarget(new targets.LambdaFunction(lambdaFunction));
71+
}
72+
}
73+
74+
```
75+
76+
5. Build project using `npm run build`
77+
6. Deploy stack using `cdk deploy`
78+
79+
*Note: This can be done without AWS CDK. Simply zip up node package and configure AWS lambda/Eventbrige via AWS console*
80+
81+
### (Optional) To submit skill for certification after skill update.
82+
Modify the `runInteractionModelUpdateWorkflow` function in `index.js` to the following to submit skill for instant publish.
83+
84+
*Note: Skill will not instant publish if there are changes other than catalog values.*
85+
86+
```
87+
async function runInteractionModelUpdateWorkflow() {
88+
try {
89+
await createDirectories();
90+
await createInteractionModelCatalogVersion();
91+
await getSkillPackageAndUpdateCatalogVersion();
92+
await submitSkillForCertification();
93+
} catch (error) {
94+
console.error('Error when running update workflow', error);
95+
throw new Error('Workflow failed', {cause: error});
96+
}
97+
}
98+
```

THIRD_PARTY_LICENSES.zip

5.13 KB
Binary file not shown.

0 commit comments

Comments
 (0)