Skip to content

Commit 398688d

Browse files
authored
feat: run interactions lambda on nodejs18 (#12482)
* feat: run interactions lambda on nodejs18 * chore: fix this
1 parent 085b244 commit 398688d

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

packages/amplify-category-interactions/src/provider-utils/awscloudformation/cloudformation-templates/lex-cloudformation-template.json.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
},
6767
"Role": { "Fn::GetAtt" : ["LambdaExecutionRole", "Arn"] },
6868
"Environment": {"Variables" : { "ENV": {"Ref": "env"}}},
69-
"Runtime": "nodejs16.x",
69+
"Runtime": "nodejs18.x",
7070
"Timeout": 300
7171
}
7272
},

packages/amplify-category-interactions/src/provider-utils/awscloudformation/function-template-dir/index.js.ejs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
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({});
59
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') {
812
let botName = "<%- props.botName %>";
913
if(process.env.ENV && process.env.ENV !== "NONE") {
1014
botName = botName + '_' + process.env.ENV;
1115
}
12-
lex.deleteBot({name: botName}).promise()
16+
lex.send(new DeleteBotCommand({name: botName}))
1317
.then(() => {
1418
response.send(event, context, response.SUCCESS);
1519
})
1620
.catch((err) => {
17-
if (err.code !== 'ParameterNotFound') {
21+
if (err.name !== 'NotFoundException') {
1822
response.send(event, context, response.FAILED);
1923
} else {
2024
response.send(event, context, response.SUCCESS);
@@ -157,7 +161,7 @@ exports.handler = function(event, context) {
157161
"voiceId": "<%- props.outputVoice %>",
158162
<% } %>
159163
<% if(props.sessionTimeout) { %>
160-
"idleSessionTTLInSeconds": "<%- props.sessionTimeout*60 %>"
164+
"idleSessionTTLInSeconds": <%- props.sessionTimeout*60 %>
161165
<% } %>
162166
};
163167

@@ -190,13 +194,13 @@ function checkAndCreateLexServiceRole() {
190194

191195
function createNewLexServiceRole() {
192196

193-
// Lex service automatically creates the needed polcies and truust relationships
197+
// Lex service automatically creates the needed policies and trust relationships
194198
const params = {
195199
AWSServiceName: 'lex.amazonaws.com',
196200
Description: 'Allows Amazon Lex to create and manage voice enabled bots on your behalf'
197201
};
198202

199-
return iam.createServiceLinkedRole(params).promise();
203+
return iamClient.send(new CreateServiceLinkedRoleCommand(params));
200204

201205
}
202206

@@ -207,7 +211,7 @@ function checkIfLexServiceRoleExists() {
207211
RoleName: "AWSServiceRoleForLexBots"
208212
};
209213

210-
return iam.getRole(params).promise()
214+
return iamClient.send(new GetRoleCommand(params))
211215
.then((result) => {
212216
rolePresent = true;
213217
return rolePresent;
@@ -226,7 +230,7 @@ function getSlotTypes(newSlotTypeParams, lex){
226230
'version': '$LATEST'
227231
};
228232
tasks.push(
229-
lex.getSlotType(params).promise()
233+
lex.send(new GetSlotTypeCommand(params))
230234
.then((data)=>{
231235
slotType['checksum'] = data.checksum;
232236
})
@@ -241,7 +245,7 @@ function putSlotTypes(newSlotTypeParams, lex){
241245
const tasks = [];
242246
newSlotTypeParams.forEach( slotType => {
243247
tasks.push(
244-
lex.putSlotType(slotType).promise()
248+
lex.send(new PutSlotTypeCommand(slotType))
245249
.then((data)=>{
246250
console.log(data);
247251
})
@@ -262,7 +266,7 @@ function getIntents(intentParams, lex){
262266
'name': intent.name
263267
};
264268
tasks.push(
265-
lex.getIntent(params).promise()
269+
lex.send(new GetIntentCommand(params))
266270
.then((data)=>{
267271
intent['checksum'] = data.checksum;
268272
})
@@ -280,7 +284,7 @@ function putIntents(intentParams, lex){
280284
ensureLambdaFunctionAccess(intent)
281285
.then(()=>{
282286
delete intent.fulfillmentLambda;
283-
return lex.putIntent(intent).promise();
287+
return lex.send(new PutIntentCommand(intent));
284288
})
285289
.then((data)=>{
286290
console.log(data);
@@ -311,7 +315,7 @@ function ensureLambdaFunctionAccess(intent){
311315
SourceArn: `arn:aws:lex:${region}:${accountId}:intent:${intent.name}:*`,
312316
}
313317

314-
return lambdaClient.addPermission(params).promise()
318+
return lambdaClient.send(new AddPermissionCommand(params))
315319
.then((data)=>{
316320
console.log(data);
317321
return data;
@@ -330,7 +334,7 @@ function getBot(botParams, lex){
330334
'name': botParams.name,
331335
'versionOrAlias': '$LATEST'
332336
};
333-
return lex.getBot(params).promise()
337+
return lex.send(new GetBotCommand(params))
334338
.then((data)=>{
335339
botParams['checksum'] = data.checksum;
336340
})
@@ -339,7 +343,7 @@ function getBot(botParams, lex){
339343
}
340344

341345
function putBot(botParams, lex){
342-
return lex.putBot(botParams).promise()
346+
return lex.send(new PutBotCommand(botParams))
343347
.then((data)=>{
344348
console.log(data);
345349
return data;
@@ -348,4 +352,4 @@ function putBot(botParams, lex){
348352
console.log(err);
349353
throw err;
350354
});
351-
}
355+
}

0 commit comments

Comments
 (0)