Skip to content

Commit ba1c6c9

Browse files
committed
Fix example
1 parent 72141fa commit ba1c6c9

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

examples/sqs-worker/src/worker.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,21 @@ class SQSWorker {
2727
const roleArn = process.env.AWS_ROLE_ARN;
2828
const sessionName = process.env.AWS_ROLE_SESSION_NAME;
2929
const externalId = process.env.AWS_EXTERNAL_ID;
30-
const durationSeconds = parseInt(process.env.AWS_ROLE_DURATION || '3600');
30+
31+
// Parse and validate AWS_ROLE_DURATION with proper error handling
32+
let durationSeconds = 3600; // Default: 1 hour
33+
if (process.env.AWS_ROLE_DURATION) {
34+
const parsedDuration = parseInt(process.env.AWS_ROLE_DURATION, 10);
35+
if (isNaN(parsedDuration)) {
36+
console.warn(`⚠️ Invalid AWS_ROLE_DURATION value: "${process.env.AWS_ROLE_DURATION}". Using default: ${durationSeconds} seconds`);
37+
} else if (parsedDuration < 900) {
38+
console.warn(`⚠️ AWS_ROLE_DURATION too low: ${parsedDuration}s (minimum: 900s). Using default: ${durationSeconds} seconds`);
39+
} else if (parsedDuration > 43200) {
40+
console.warn(`⚠️ AWS_ROLE_DURATION too high: ${parsedDuration}s (maximum: 43200s). Using default: ${durationSeconds} seconds`);
41+
} else {
42+
durationSeconds = parsedDuration;
43+
}
44+
}
3145

3246
if (roleArn && sessionName) {
3347
// Use AssumeRole credentials

0 commit comments

Comments
 (0)