1
1
const response = require('./cfn-response');
2
- const aws = require('aws-sdk');
3
- const iam = new aws.IAM();
4
- const lambdaClient = new aws.Lambda({ apiVersion: '2017-04-19' });
2
+ const { IAMClient, CreateServiceLinkedRoleCommand, GetRoleCommand } = require('@aws-sdk/client-iam');
3
+ const { LambdaClient, AddPermissionCommand} = require('@aws-sdk/client-lambda');
4
+ const { LexModelBuildingServiceClient, DeleteBotCommand, GetSlotTypeCommand, PutSlotTypeCommand, GetIntentCommand,
5
+ PutIntentCommand, GetBotCommand, PutBotCommand
6
+ } = require('@aws-sdk/client-lex-model-building-service');
7
+ const iamClient = new IAMClient({});
8
+ const lambdaClient = new LambdaClient({});
5
9
exports.handler = function(event, context) {
6
- const lex = new aws.LexModelBuildingService({ apiVersion: '2017-04-19', region: event.ResourceProperties.lexRegion });
7
- if (event.RequestType == 'Delete') {
10
+ const lex = new LexModelBuildingServiceClient({ region: event.ResourceProperties.lexRegion });
11
+ if (event.RequestType === 'Delete') {
8
12
let botName = "<% - props .botName %> ";
9
13
if(process.env.ENV && process.env.ENV !== "NONE") {
10
14
botName = botName + '_' + process.env.ENV;
11
15
}
12
- lex.deleteBot( {name: botName}).promise( )
16
+ lex.send(new DeleteBotCommand( {name: botName}))
13
17
.then(() => {
14
18
response.send(event, context, response.SUCCESS);
15
19
})
16
20
.catch((err) => {
17
- if (err.code !== 'ParameterNotFound ') {
21
+ if (err.name !== 'NotFoundException ') {
18
22
response.send(event, context, response.FAILED);
19
23
} else {
20
24
response.send(event, context, response.SUCCESS);
@@ -157,7 +161,7 @@ exports.handler = function(event, context) {
157
161
" voiceId" : " <%- props.outputVoice %>" ,
158
162
< % } %>
159
163
<% if (props .sessionTimeout ) { % >
160
- " idleSessionTTLInSeconds" : " <%- props.sessionTimeout*60 %>"
164
+ " idleSessionTTLInSeconds" : < %- props .sessionTimeout * 60 % >
161
165
< % } %>
162
166
};
163
167
@@ -190,13 +194,13 @@ function checkAndCreateLexServiceRole() {
190
194
191
195
function createNewLexServiceRole() {
192
196
193
- // Lex service automatically creates the needed polcies and truust relationships
197
+ // Lex service automatically creates the needed policies and trust relationships
194
198
const params = {
195
199
AWSServiceName: 'lex.amazonaws.com',
196
200
Description: 'Allows Amazon Lex to create and manage voice enabled bots on your behalf'
197
201
};
198
202
199
- return iam.createServiceLinkedRole( params).promise( );
203
+ return iamClient.send(new CreateServiceLinkedRoleCommand( params));
200
204
201
205
}
202
206
@@ -207,7 +211,7 @@ function checkIfLexServiceRoleExists() {
207
211
RoleName: "AWSServiceRoleForLexBots"
208
212
};
209
213
210
- return iam.getRole( params).promise( )
214
+ return iamClient.send(new GetRoleCommand( params))
211
215
.then((result) => {
212
216
rolePresent = true;
213
217
return rolePresent;
@@ -226,7 +230,7 @@ function getSlotTypes(newSlotTypeParams, lex){
226
230
'version': '$LATEST'
227
231
};
228
232
tasks.push(
229
- lex.getSlotType( params).promise( )
233
+ lex.send(new GetSlotTypeCommand( params))
230
234
.then((data)=>{
231
235
slotType['checksum'] = data.checksum;
232
236
})
@@ -241,7 +245,7 @@ function putSlotTypes(newSlotTypeParams, lex){
241
245
const tasks = [];
242
246
newSlotTypeParams.forEach( slotType => {
243
247
tasks.push(
244
- lex.putSlotType( slotType).promise( )
248
+ lex.send(new PutSlotTypeCommand( slotType))
245
249
.then((data)=>{
246
250
console.log(data);
247
251
})
@@ -262,7 +266,7 @@ function getIntents(intentParams, lex){
262
266
'name': intent.name
263
267
};
264
268
tasks.push(
265
- lex.getIntent( params).promise( )
269
+ lex.send(new GetIntentCommand( params))
266
270
.then((data)=>{
267
271
intent['checksum'] = data.checksum;
268
272
})
@@ -280,7 +284,7 @@ function putIntents(intentParams, lex){
280
284
ensureLambdaFunctionAccess(intent)
281
285
.then(()=>{
282
286
delete intent.fulfillmentLambda;
283
- return lex.putIntent( intent).promise( );
287
+ return lex.send(new PutIntentCommand( intent));
284
288
})
285
289
.then((data)=>{
286
290
console.log(data);
@@ -311,7 +315,7 @@ function ensureLambdaFunctionAccess(intent){
311
315
SourceArn: `arn:aws:lex:${region}:${accountId}:intent:${intent.name}:*`,
312
316
}
313
317
314
- return lambdaClient.addPermission( params).promise( )
318
+ return lambdaClient.send(new AddPermissionCommand( params))
315
319
.then((data)=>{
316
320
console.log(data);
317
321
return data;
@@ -330,7 +334,7 @@ function getBot(botParams, lex){
330
334
'name': botParams.name,
331
335
'versionOrAlias': '$LATEST'
332
336
};
333
- return lex.getBot( params).promise( )
337
+ return lex.send(new GetBotCommand( params))
334
338
.then((data)=>{
335
339
botParams['checksum'] = data.checksum;
336
340
})
@@ -339,7 +343,7 @@ function getBot(botParams, lex){
339
343
}
340
344
341
345
function putBot(botParams, lex){
342
- return lex.putBot( botParams).promise( )
346
+ return lex.send(new PutBotCommand( botParams))
343
347
.then((data)=>{
344
348
console.log(data);
345
349
return data;
@@ -348,4 +352,4 @@ function putBot(botParams, lex){
348
352
console.log(err);
349
353
throw err;
350
354
});
351
- }
355
+ }
0 commit comments