Package: cdk-skill-management
cdk-skill-managementSince I am only working with Node.js and TypeScript, the Python package is currently not tested / used.
Therefore I am looking for someone to use and test it to provide feedback, if the library is actually working and if there are best practices to apply (e.g. namings, module name, etc.).Your library for creating and managing Alexa Skills via CloudFormation using AWS CDK.Table of ContentsInstallationUsageContributingLicenseChangelogInstallationNode.js / TypeScriptTo install the Node.js version of this library, use npm or yarn:npminstallcdk-skill-management# oryarnaddcdk-skill-managementPythonTo install the Python version of this library, use pip:pipinstallcdk-skill-managementUsageTo use this library in your AWS CDK project, import and instantiate the classes you need.You can find the API-Documentation inGitHub Pages.Regional restrictionsSkills can be deployed in every AWS regions, but Lambda Endpoints are restricted toNorth America:arn:aws:lambda:us-east-1:<aws_account_id>:function:<lambda_name>Europe, India:arn:aws:lambda:eu-west-1:<aws_account_id>:function:<lambda_name>Far East:arn:aws:lambda:location<aws_account_id>:function:<lambda_name>CDK deployment orderYou can useskillPackage.overridesto patch your lambda function ARN into your skill package.Make sure to calladdDependencyon your skill instance.Skill PermissionsIn order for Alexa to call the skill endpoint - i.e. the Lambda function - a resource based permission must be added to allow the Alexa Service Principal to call the function.
However, this would cause any Alexa Skill to be able to call the endpoint. Therefore, the skill-id should be added as a condition to the permission.However, when deploying the skill, Alexa immediately checks if the skill endpoint is allowed to be accessed. At this point, we do not have a skill id to add to the resource based permission.Therefore, this library includes a constructSkillEndpointPermission, which first creates a resource based permission that allows Alexa to callinvokeFunctionin general.After the creation of the Skill, the Skill Id can be injected into the Permission. To do this, simply call theconfigureSkillIdmethod on theSkillEndpointPermission.ExampleHere's an example including theskillPackage.overridesandSkillEndpointPermission.import*ascdkfrom'aws-cdk-lib';import*aslambdafrom'aws-cdk-lib/aws-lambda';import*ass3Assetsfrom'aws-cdk-lib/aws-s3-assets';import*assecretsmanagerfrom'aws-cdk-lib/aws-secretsmanager';import*asssmfrom'aws-cdk-lib/aws-ssm';import{Construct}from'constructs';import*asskillfrom'cdk-skill-management';exportclassMyStackextendscdk.Stack{constructor(scope:Construct,id:string,props:cdk.StackProps={}){super(scope,id,props);constvendorParameter=ssm.StringParameter.fromStringParameterName(this,'VendorIdParameter','my-skill-vendor-id');constskillCredentials=secretsmanager.Secret.fromSecretNameV2(this,'SkillCredentials','my-skill-authentication');constasset=news3Assets.Asset(this,'SkillPackageAsset',{path:'./path/to/my/skill-package'});constmyFunction=newlambda.Function(this,'MyEndpointFunction',{...});constendpointPermission=newskill.SkillEndpointPermission(this,'EndpointPermission',{handler:myFunction,skillType:skill.SkillType.SMART_HOME,});constmySkill=newskill.Skill(this,'Skill',{skillType:skill.SkillType.SMART_HOME,skillStage:'development',vendorId:vendorParameter.stringValue,authenticationConfiguration:{clientId:skillCredentials.secretValueFromJson('clientId').unsafeUnwrap(),clientSecret:skillCredentials.secretValueFromJson('clientSecret').unsafeUnwrap(),refreshToken:skillCredentials.secretValueFromJson('refreshToken').unsafeUnwrap(),},skillPackage:{asset,overrides:{manifest:{apis:{smartHome:{endpoint:{uri:myFunction.functionArn}}}}}},});mySkill.addDependency(myFunction);mySkill.addDependency(endpointPermission);endpointPermission.configureSkillId(this,'EndpointPermissionSkill',mySkill);}}ContributingWe welcome contributions from the community. To contribute, please follow ourcontribution guidelines.LicenseThis library is licensed under the MIT License - see theLICENSEfile for details.This library bundlesask-smapi-sdkandask-smapi-modelinto a custom resource lambda function.
Those are licensed under the Apache License 2.0 - see theLICENSE-EXTERNALfor details.