Skip to content

Commit a90631f

Browse files
authored
adds studio login triggers troubleshooting info (#7596)
* add studio trigger troubleshooting info * update doc
1 parent 63ac325 commit a90631f

File tree

5 files changed

+102
-0
lines changed

5 files changed

+102
-0
lines changed

cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"AmplifyAngularModule",
8787
"amplifyapp.com",
8888
"amplifyapp",
89+
"amplifybackend",
8990
"amplifyhosting",
9091
"amplifyconfiguration.json",
9192
"amplifyconfiguration",
Loading
64 KB
Loading
178 KB
Loading

src/pages/gen1/[platform]/tools/console/adminui/access-management/index.mdx

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,104 @@ If your Studio application experiences any issues logging in or the resources ha
114114
If you receive an error that you're not authorized to perform an action, your policies must be updated to allow you to perform the action.
115115

116116
If you need help, contact your AWS administrator. Your administrator is the person who provided you with your sign-in credentials. See [AWS managed policies for AWS Amplify](https://docs.aws.amazon.com/amplify/latest/userguide/security-iam-awsmanpol.html) for more details.
117+
118+
### Updating Login Cognito Lambda triggers runtime
119+
120+
If you need to update the [Cognito Lambda triggers](/gen1/[platform]/tools/console/adminui/access-management/#cognito-lambda-triggers) runtime, you can do so by updating the Lambda functions triggers associated with the Cognito User Pool named **`amplify_backend_manager_<app-id>`**.
121+
122+
1. Log in to the **AWS Management Console**, open the **Amplify console** and select your Amplify project with Amplify Studio enabled.
123+
2. Retrieve the App ID present on the overview page under the App name.
124+
3. Go to **Amazon Cognito console**, select **User pools**. Search for the user pool with the App Id. You will observe the app user pool with the naming format `amplify_backend_manager_<app-id>`.
125+
4. Select the user pool and go to **User Pool Properties** which should display the **Lambda Triggers**.
126+
![Cognito Lambda Triggers created by studio](/images/studio/lambda-triggers-studio.png)
127+
5. For each lambda trigger, select the link specified in the **Attached Lambda Function** column. Note, If your lambda trigger is **Verify auth challenge response Lambda trigger** the function requires additional steps provided on [Update verify auth challenge response Lambda trigger](/gen1/[platform]/tools/console/adminui/access-management/#update-verify-auth-challenge-response-lambda-trigger) section.
128+
6. Select **Edit runtime settings** and change the runtime to **Node.js 20.x** from the drop-down options.
129+
![Lambda runtime](/images/studio/lambda_runtime.png)
130+
7. Finally, select **Save**.
131+
132+
### Update verify auth challenge response Lambda trigger
133+
134+
This function requires code change as Lambda with **NodeJS 20.x** use a newer version of **aws-sdk**.
135+
136+
1. Go to Lambda Code Source and select `index.js` file.
137+
![Lambda source code section for a Cognito trigger resource](/images/studio/trigger_source_code.png)
138+
2. Replace the contents of `index.js` with the following:
139+
140+
```js
141+
const { AmplifyBackendClient, GetTokenCommand, DeleteTokenCommand } = require('@aws-sdk/client-amplifybackend');
142+
143+
exports.handler = async (event, context) => {
144+
try {
145+
const amplifyBackendService = new AmplifyBackendService(event);
146+
await amplifyBackendService.validateToken();
147+
console.log(`verified challenge code with result: ${event.response.answerCorrect}`);
148+
context.done(null, event);
149+
return event;
150+
} catch (e) {
151+
console.error('exception occurred during verify', e);
152+
event.response.answerCorrect = false;
153+
context.done(e, event);
154+
}
155+
};
156+
157+
class AmplifyBackendService {
158+
constructor(event) {
159+
const { sessionId, appId } = event.request.clientMetadata;
160+
const { challengeAnswer } = event.request;
161+
this.appId = appId;
162+
this.sessionId = sessionId;
163+
this.challengeAnswer = challengeAnswer;
164+
this.event = event;
165+
}
166+
167+
async validateToken() {
168+
this.amplifyBackend = this.initService();
169+
// 1. Get token
170+
const tokenResponse = await this.getToken();
171+
172+
// 2. Validate token
173+
const challengeCode = tokenResponse.ChallengeCode;
174+
if (challengeCode && this.challengeAnswer && this.challengeAnswer === challengeCode) {
175+
this.event.response.answerCorrect = true;
176+
} else {
177+
this.event.response.answerCorrect = false;
178+
}
179+
180+
// 3. Delete token
181+
await this.deleteToken();
182+
183+
return this.event.response.answerCorrect;
184+
}
185+
186+
initService() {
187+
const amplifyBackend = process.env.ENDPOINT
188+
? new AmplifyBackendClient({
189+
endpoint: process.env.ENDPOINT,
190+
})
191+
: new AmplifyBackendClient();
192+
return amplifyBackend;
193+
}
194+
195+
getToken() {
196+
return this.amplifyBackend.send(
197+
new GetTokenCommand({
198+
AppId: this.appId,
199+
SessionId: this.sessionId,
200+
}),
201+
);
202+
}
203+
204+
deleteToken() {
205+
return this.amplifyBackend.send(
206+
new DeleteTokenCommand({
207+
AppId: this.appId,
208+
SessionId: this.sessionId,
209+
}),
210+
);
211+
}
212+
}
213+
214+
exports.AmplifyBackendService = AmplifyBackendService;
215+
```
216+
217+
3. Finally, select **Deploy** to save the changes.

0 commit comments

Comments
 (0)