ask-cli
Version:
Alexa Skills Kit (ASK) Command Line Interfaces
126 lines (125 loc) • 4.81 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const client_lambda_1 = require("@aws-sdk/client-lambda");
const abstract_aws_client_1 = __importDefault(require("./abstract-aws-client"));
/**
* Class for Lambda Client
*/
class LambdaClient extends abstract_aws_client_1.default {
/**
* Constructor
* @param configuration The AWS client config
*/
constructor(configuration) {
super(configuration);
this.client = new client_lambda_1.LambdaClient({
credentials: this.credentials,
region: this.region,
});
}
/**
* Creates a lambda function
* @param functionName The name of the lambda function
* @param config The configuration of the lambda function
* @param role The arn of the iam role
* @param zipFile The base64-encoded contents of the deployment package
*/
createLambdaFunction(functionName, config, role, zipFile) {
const { runtime, handler, description, memorySize, timeout, environmentVariables } = config;
const command = new client_lambda_1.CreateFunctionCommand({
Code: {
ZipFile: zipFile,
},
FunctionName: functionName,
Handler: handler,
MemorySize: memorySize,
Role: role,
Runtime: runtime,
Timeout: timeout,
...(description && { Description: description }),
...(environmentVariables && { Environment: { Variables: environmentVariables } }),
});
return this.client.send(command);
}
/**
* Adds Alexa service permission to a lambda function
* @param skillType The skill type
* @param skillId The skill id used as a event source token
* @param functionArn The arn of the lambda function
*/
addAlexaPermissionByDomain(skillType, skillId, functionArn) {
const command = new client_lambda_1.AddPermissionCommand({
FunctionName: functionArn,
StatementId: Date.now().toString(),
Action: "lambda:InvokeFunction",
Principal: this._getAlexaServicePrincipal(skillType),
EventSourceToken: skillId,
});
return this.client.send(command);
}
/**
* Returns information for a lambda function
* @param functionArn The name of the lambda function
*/
getFunction(functionArn) {
const command = new client_lambda_1.GetFunctionCommand({
FunctionName: functionArn,
});
return this.client.send(command);
}
/**
* Updates the code for a lambda function
* @param functionArn The arn of the lambda function
* @param zipFile The base64-encoded contents of the deployment package
* @param revisionId Only update the function if the revision ID matches the ID that's specified
*/
updateFunctionCode(functionArn, zipFile, revisionId) {
const command = new client_lambda_1.UpdateFunctionCodeCommand({
FunctionName: functionArn,
ZipFile: zipFile,
RevisionId: revisionId,
});
return this.client.send(command);
}
/**
* Updates the configuration for a lambda function
* @param functionArn The arn of the lambda function
* @param config The configuration of the lambda function
* @param revisionId Only update the function if the revision ID matches the ID that's specified
*/
updateFunctionConfiguration(functionArn, config, revisionId) {
const { runtime, handler, description, memorySize, timeout, environmentVariables } = config;
const command = new client_lambda_1.UpdateFunctionConfigurationCommand({
FunctionName: functionArn,
Handler: handler,
MemorySize: memorySize,
RevisionId: revisionId,
Runtime: runtime,
Timeout: timeout,
...(description && { Description: description }),
...(environmentVariables && { Environment: { Variables: environmentVariables } }),
});
return this.client.send(command);
}
/**
* Returns the alexa service principal for a skill type
* @param skillType The skill type
*/
_getAlexaServicePrincipal(skillType) {
switch (skillType) {
case "smartHome":
case "video":
return "alexa-connectedhome.amazon.com";
case "custom":
case "houseHoldList":
case "music":
return "alexa-appkit.amazon.com";
default:
return;
}
}
}
exports.default = LambdaClient;