For the past one week, I have been trying to deploy an amplify app using cognito services and the aws-sdk for IoT, but no head-way.
I have previously deployed same using the version 2.
Recently, I cannot anymore because the cloud stack formation enforces the use of version 3.
I have taken the initiative to update my repo to version 3, updated my Runtime environment: to node 18x in my yml file, yet it still failing. Below is where I usually get stuck during stack formation:
UserPoolClientInputs:
Type: Custom::LambdaCallout
Properties:
ServiceToken:
Fn::GetAtt:
- UserPoolClientLambda
- Arn
clientId:
Ref: UserPoolClient
userpoolId:
Ref: UserPool
DependsOn: UserPoolClientLogPolicy
and then I receive the following log error from the cloudWatch:
> 2024-05-09T11:14:46.811Z undefined ERROR Uncaught Exception {
"errorType": "Runtime.ImportModuleError",
"errorMessage": "Error: Cannot find module 'aws-sdk'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/index.mjs",
"stack": [
"Runtime.ImportModuleError: Error: Cannot find module 'aws-sdk'",
"Require stack:",
"- /var/task/index.js",
"- /var/runtime/index.mjs",
" at _loadUserApp (file:///var/runtime/index.mjs:1087:17)",
" at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)",
" at async start (file:///var/runtime/index.mjs:1282:23)",
" at async file:///var/runtime/index.mjs:1288:1"
]}
Looking at my yml file that request the aws-sdk is as below:
Type: AWS::Lambda::Function
Properties:
Code:
ZipFile:
Fn::Join:
- ''
- - const response = require('cfn-response');
- const aws = require('aws-sdk');
- const identity = new aws.CognitoIdentityServiceProvider();
- exports.handler = (event, context, callback) => {
- ' if (event.RequestType == ''Delete'') { '
- ' response.send(event, context, response.SUCCESS, {})'
- ' }'
- ' if (event.RequestType == ''Update'' || event.RequestType == ''Create'') {'
- ' const params = {'
- ' ClientId: event.ResourceProperties.clientId,'
- ' UserPoolId: event.ResourceProperties.userpoolId'
- ' };'
- ' identity.describeUserPoolClient(params).promise()'
- ' .then((res) => {'
- ' response.send(event, context, response.SUCCESS, {''appSecret'': res.UserPoolClient.ClientSecret});'
- ' })'
- ' .catch((err) => {'
- ' response.send(event, context, response.FAILURE, {err});'
- ' });'
- ' }'
- '};'
Handler: index.handler
Runtime: nodejs18.x
Timeout: '300'
Role:
Fn::GetAtt:
- UserPoolClientRole
- Arn
DependsOn: UserPoolClientRole```
I need a guide on the best approach to make it work. I already have installed aws-sdk v3 as a dependency below:
dependencies: {
"@aws-sdk/client-cloudformation": "^3.569.0",
"@aws-sdk/client-s3": "^3.569.0",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"aws-amplify": "^1.3.3",
"aws-amplify-react": "^2.6.3",
"aws-iot-device-sdk": "^2.2.13"
}
your help is highly anticipated.
Thanks
Can you try updating the function in the yaml file to use v3 equivalent instead of v2?