Amazon Alexaask-cli

Run self-customized ASK-CLI command

ASK CLI (version 2) is OSS, so we can request a new feature to the product owner by a Pull Request in GitHub.B […]

広告ここから
広告ここまで

ASK CLI (version 2) is OSS, so we can request a new feature to the product owner by a Pull Request in GitHub.
But, sometimes we can not wait their decision to merge/release our Pull Request.

Today, I’ll blog about how to use self-customized ASK CLI command.

Pros

We can easy to customize the CLI command by ourselves.
Once create a Pull Request, during waiting for the maintenance team feedback, we can already use the feature in our local.

Cons

Of cause, we have to self-maintain the forked CLI.
Or we have to change the ask command path per project or per release.

Steps of customize

Step1: Fork and setup the project in GitHub

We have to fork the project in GitHub. And clone the forked project in our own local.

$ git clone git@github.com:YOUR_USERNAME/ask-cli.git
$ cd ask-cli
$ npm install

Step2: Customize the CLI code

We can customize the CLI code in our local.

This is the example of customize.

--- a/lib/builtins/deploy-delegates/cfn-deployer/helper.js
+++ b/lib/builtins/deploy-delegates/cfn-deployer/helper.js
@@ -19,6 +19,13 @@ module.exports = {
     deployStack,
 };
 
+function getS3BucketName(awsProfile, awsRegion, userConfig, deployState) {
+    const currentBucketName = R.view(R.lensPath(['s3', 'bucket']), deployState);
+    if (currentBucketName) return currentBucketName;
+    if (userConfig.deploymentBucket) return userConfig.deploymentBucket;
+    return S3Client.generateBucketName(awsProfile, awsRegion);
+}
+
 function getAwsInformation(awsProfile, alexaRegion, userConfig, deployState) {
     let awsRegion = alexaRegion === 'default' ? userConfig.awsRegion
         : R.view(R.lensPath(['regionalOverrides', alexaRegion, 'awsRegion']), userConfig);
@@ -32,7 +39,7 @@ function getAwsInformation(awsProfile, alexaRegion, userConfig, deployState) {
         throw 'The template path in userConfig must be provided.';
     }
 
-    const bucketName = R.view(R.lensPath(['s3', 'bucket']), deployState) || S3Client.generateBucketName(awsProfile, awsRegion);
+    const bucketName = getS3BucketName(awsProfile, awsRegion, userConfig, deployState);

// from https://github.com/alexa/ask-cli/pull/134/files#diff-c169b6c84cc10becf8a53c0aff03a126

I want to use a specific S3 bucket to deploy the Lambda function to AWS by CloudFormation.

So, I’ve customized the CLI code for this property to be selectable.

Step3: Run the customized CLI in local

Finally, we can use the self-customized CLI from node command.

// Check the forked project directory
$ pwd
/Users/develop/ask-cli

// Run the forked CLI
$ node /Users/develop/ask-cli/bin/ask.js --help

In my example, I can use a specific S3 bucket for the stack deployment!

$ node /Users/develop/ask-cli/bin/ask.js deploy

==================== Deploy Skill Metadata ====================
Skill package deployed successfully.
Skill ID: amzn1.ask.skill.xxxx-xxx-xxx-xxx

==================== Build Skill Code ====================
npm WARN hello-world@1.1.0 No repository field.

added 17 packages from 69 contributors and audited 20 packages in 1.875s
found 0 vulnerabilities

Skill code built successfully.
Code for region default built to /Users/develop/ForkedExample/.ask/lambda/build.zip successfully with build flow nodejs-npm.

==================== Deploy Skill Infrastructure ====================
{
  bucketName: 'my.custom.s3.bucket',
  bucketObjectVersion: undefined
}
  ⠴ Deploy Alexa skill infrastructure for region "default"
    → Uploading code artifact to s3://my.custom.s3.bucket/endpoint/build.zip

Conclusion

We can easy to customize the ASK CLI feature in our local.

But the way of customizing is a temporary solution.

I strongly recommend making a Pull Request to the GitHub repository to request to add the feature you want.

ブックマークや限定記事(予定)など

WP Kyotoサポーター募集中

WordPressやフロントエンドアプリのホスティング、Algolia・AWSなどのサービス利用料を支援する「WP Kyotoサポーター」を募集しています。
月額または年額の有料プランを契約すると、ブックマーク機能などのサポーター限定機能がご利用いただけます。

14日間のトライアルも用意しておりますので、「このサイトよく見るな」という方はぜひご検討ください。

広告ここから
広告ここまで

Related Category posts