Skip to content

feat: support standard AWS env vars and default credential chain - #395

Closed
purva-8 wants to merge 3 commits into
usesend:mainfrom
purva-8:feat/standard-aws-env-vars
Closed

feat: support standard AWS env vars and default credential chain#395
purva-8 wants to merge 3 commits into
usesend:mainfrom
purva-8:feat/standard-aws-env-vars

Conversation

@purva-8

@purva-8purva-8 commented May 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes#316

  • RenameAWS_ACCESS_KEYAWS_ACCESS_KEY_ID and AWS_SECRET_KEYAWS_SECRET_ACCESS_KEY to match the AWS standard naming convention used by the SDK, CLI, and IAM tooling
  • Make credentials optional: both vars are now z.string().optional() in the env schema
  • Default credential chain: when the vars are absent, the credentials object is omitted from SESv2Client, STSClient, and SNSClient — the AWS SDK automatically falls back to its default provider chain (IAM roles, ECS/EKS task roles, EC2 instance profiles, ~/.aws/credentials, etc.)
  • Backward compatibility: the runtimeEnv falls back to the old names (?? process.env.AWS_ACCESS_KEY) so existing deployments don't break without a config change

Files changed

FileChange
apps/web/src/env.jsRename schema keys, make optional, add backward-compat fallback
apps/web/src/server/aws/ses.tsConditionally pass credentials to SESv2Client / STSClient
apps/web/src/server/aws/sns.tsConditionally pass credentials to SNSClient
apps/web/src/test/setup/setup-env.tsUpdate test env keys
apps/web/.env.test.exampleUpdate example keys
.env.exampleUpdate example keys
.env.selfhost.exampleUpdate example keys, improve comment

Test plan

  • Existing deployments using the old AWS_ACCESS_KEY / AWS_SECRET_KEY names continue to work (backward-compat fallback)
  • Deployments using the new AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY names work
  • Deployments on ECS/EKS/EC2 with an IAM role and no credential env vars can boot and send email via the default provider chain
  • Unit tests pass (pnpm test)

Summary by cubic

Switches to AWS-standard env vars AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY and uses the AWS default credential chain when unset. Adds a shared credential helper that errors on partial configs; keeps backward compatibility and only passes credentials to SESv2, STS, and SNS when both vars are set.

  • New Features

    • Credentials are optional; SDK default chain is used when unset.
    • New getAwsCredentialOptions centralizes logic for SESv2Client, STSClient, and SNSClient.
    • Throws if only one of AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY is set.
  • Migration

    • Rename AWS_ACCESS_KEYAWS_ACCESS_KEY_ID and AWS_SECRET_KEYAWS_SECRET_ACCESS_KEY.
    • On IAM-role deployments, omit these vars to rely on the default chain.
    • Existing setups using old names keep working; migrate when convenient.

Written for commit 5c816be. Summary will update on new commits.

Summary by CodeRabbit

  • Chores
    • Renamed AWS credential environment variables from AWS_ACCESS_KEY/AWS_SECRET_KEY to AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY across examples and test configs.
    • Updated runtime validation to accept the new variables while falling back to the legacy names for compatibility.
    • Added credential-handling checks to ensure both new variables are set together (or omitted) to avoid misconfiguration.

Replace non-standard AWS_ACCESS_KEY / AWS_SECRET_KEY with the AWS-standard
AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY. The old names are kept as
fallbacks in the runtimeEnv for backward compatibility.
Both vars are now optional. When omitted, the credentials object is not
passed to SESv2Client, STSClient, or SNSClient — the AWS SDK then falls
back to its default provider chain (IAM roles, ECS task roles, instance
profiles, etc.), which is the recommended approach for cloud-native deployments.
Closesusesend#316
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
CopilotAI review requested due to automatic review settings May 2, 2026 12:24
@vercel

vercelBot commented May 2, 2026

Copy link
Copy Markdown

@purva-8 is attempting to deploy a commit to the kmkoushik's projects Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai

coderabbitaiBot commented May 2, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request updates AWS credential variable naming conventions across the codebase. Environment configuration files (.env.example, .env.selfhost.example, and apps/web/.env.test.example) are modified to use standard AWS naming (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY instead of AWS_ACCESS_KEY and AWS_SECRET_KEY). The environment schema in apps/web/src/env.js is updated to validate these new optional variables with fallback support for legacy names. AWS service clients in ses.ts and sns.ts are refactored to conditionally inject credentials using the new variable names. Test environment setup is similarly updated to populate the new credential variable names.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe title accurately summarizes the main changes: supporting standard AWS environment variables and enabling use of the default credential chain.
Linked Issues check✅ PassedAll coding requirements from issue #316 are met: standard AWS env vars are supported, credentials are optional, and the default credential chain can be used.
Out of Scope Changes check✅ PassedAll changes directly support the PR objectives of renaming AWS variables, making credentials optional, and maintaining backward compatibility.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 6/8 reviews remaining, refill in 9 minutes and 41 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the web app’s AWS credential handling to support standard AWS environment variable names and to allow the AWS SDK default credential provider chain when static credentials aren’t provided (fixing #316).

Changes:

  • Renames AWS_ACCESS_KEY / AWS_SECRET_KEY to AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY (with legacy fallback).
  • Makes AWS credential env vars optional and conditionally omits the credentials override for AWS SDK clients.
  • Updates test setup and example env files to reflect the new variable names.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
FileDescription
apps/web/src/env.jsUpdates env schema keys and adds legacy fallback in runtimeEnv.
apps/web/src/server/aws/ses.tsConditionally passes credentials to STSClient and SESv2Client.
apps/web/src/server/aws/sns.tsConditionally passes credentials to SNSClient.
apps/web/src/test/setup/setup-env.tsUpdates test env defaults to new AWS credential keys.
apps/web/.env.test.exampleUpdates example AWS credential keys for tests.
.env.exampleUpdates example AWS credential keys for local/dev.
.env.selfhost.exampleUpdates example keys and clarifies optional credential chain usage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadapps/web/src/env.js Outdated
Comment threadapps/web/src/env.js
Comment threadapps/web/src/server/aws/ses.ts Outdated
Comment threadapps/web/src/server/aws/sns.ts Outdated

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/web/src/server/aws/ses.ts (1)

33-35: ⚡ Quick win

Extract the repeated credential-options construction to a shared helper.

The same conditional spread appears three times: STS client (Line 33–35), SES client (Line 52–54), and the SNS client in sns.ts (Line 13–15). If the logic ever needs to add sessionToken or change the guard condition, all three sites must be updated in sync.

♻️ Proposed refactor

Add a shared helper (e.g. in apps/web/src/server/aws/credentials.ts):

import{env}from"~/env";exportfunctiongetAwsCredentialOptions(){if(env.AWS_ACCESS_KEY_ID&&env.AWS_SECRET_ACCESS_KEY){return{credentials: {accessKeyId: env.AWS_ACCESS_KEY_ID,secretAccessKey: env.AWS_SECRET_ACCESS_KEY,},};}return{};}

Then in ses.ts:

- ...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY- ? { credentials: { accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY } }- : {}),+ ...getAwsCredentialOptions(),

Apply the same replacement in the second occurrence in ses.ts and in sns.ts.

Also applies to: 52-54

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/web/src/server/aws/ses.ts` around lines 33 - 35, Extract the repeated
conditional credential spread into a shared helper (e.g.
getAwsCredentialOptions) that reads env.AWS_ACCESS_KEY_ID and
env.AWS_SECRET_ACCESS_KEY and returns either { credentials: { accessKeyId,
secretAccessKey } } or {}; then replace the inline conditional spread used when
constructing the STS client, SES client (the block containing
...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY ? { credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY }
} : {}) in ses.ts) and the SNS client in sns.ts with a call to
getAwsCredentialOptions(), ensuring the helper is exported from a common module
(e.g. credentials.ts) and imported where needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/web/src/server/aws/ses.ts`:
- Around line 33-35: Extract the repeated conditional credential spread into a
shared helper (e.g. getAwsCredentialOptions) that reads env.AWS_ACCESS_KEY_ID
and env.AWS_SECRET_ACCESS_KEY and returns either { credentials: { accessKeyId,
secretAccessKey } } or {}; then replace the inline conditional spread used when
constructing the STS client, SES client (the block containing
...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY ? { credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY }
} : {}) in ses.ts) and the SNS client in sns.ts with a call to
getAwsCredentialOptions(), ensuring the helper is exported from a common module
(e.g. credentials.ts) and imported where needed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 59ef1c51-59a4-4cf8-9644-0f3ad9c00c0f

📥 Commits

Reviewing files that changed from the base of the PR and between 964bbf9 and 83258bf.

📒 Files selected for processing (7)
  • .env.example
  • .env.selfhost.example
  • apps/web/.env.test.example
  • apps/web/src/env.js
  • apps/web/src/server/aws/ses.ts
  • apps/web/src/server/aws/sns.ts
  • apps/web/src/test/setup/setup-env.ts

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/web/src/env.js`:
- Around line 34-35: The environment schema currently allows AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY to be set independently which lets code in
apps/web/src/server/aws/ses.ts and apps/web/src/server/aws/sns.ts silently fall
back to the default provider when only one credential is present; update the zod
schema for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to validate they are
either both present or both absent (e.g., using a .refine or a custom validator)
so the app fails fast with a clear error when only one credential is provided,
and ensure any code that reads these vars (SES/SNS initialization) relies on
that validated pair rather than tolerating partial config.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d7aa3fb3-6172-4517-80bd-b5a93802008a

📥 Commits

Reviewing files that changed from the base of the PR and between 83258bf and 4277fb8.

📒 Files selected for processing (1)
  • apps/web/src/env.js

Comment threadapps/web/src/env.js
…al-config guard
- Move the credential spread logic into a single credentials.ts helper
so SESv2Client, STSClient, and SNSClient all share one implementation
- Throw a clear error if only one of AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY
is set, preventing silent fallback to the default provider chain with a
half-configured environment
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/web/src/server/aws/credentials.ts`:
- Around line 4-19: The credentials helper currently only returns accessKeyId
and secretAccessKey, which breaks temporary AWS creds; add support for
AWS_SESSION_TOKEN by adding AWS_SESSION_TOKEN to your env.js schema and
runtimeEnv, then update the return object in
apps/web/src/server/aws/credentials.ts to conditionally include sessionToken
(e.g., when env.AWS_SESSION_TOKEN is present, add credentials.sessionToken =
env.AWS_SESSION_TOKEN) alongside accessKeyId and secretAccessKey, and update
test fixtures and .env.example to include an optional AWS_SESSION_TOKEN entry so
temporary credential flows are exercised.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2d02e951-f64f-4566-99ee-986b878bc362

📥 Commits

Reviewing files that changed from the base of the PR and between 4277fb8 and 5c816be.

📒 Files selected for processing (3)
  • apps/web/src/server/aws/credentials.ts
  • apps/web/src/server/aws/ses.ts
  • apps/web/src/server/aws/sns.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/src/server/aws/sns.ts
  • apps/web/src/server/aws/ses.ts

Comment on lines +4 to +19
const hasKey = !!env.AWS_ACCESS_KEY_ID;
const hasSecret = !!env.AWS_SECRET_ACCESS_KEY;

if (hasKey !== hasSecret) {
throw new Error(
"AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must both be set or both be omitted"
);
}

if (hasKey) {
return {
credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID!,
secretAccessKey: env.AWS_SECRET_ACCESS_KEY!,
},
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash# Verify whether AWS_SESSION_TOKEN is modeled and propagated in current PR surface.# Expected: references in env schema/mapping + credentials helper + (optionally) env examples.
rg -n -C3 '\bAWS_SESSION_TOKEN\b' \
apps/web/src/env.js \
apps/web/src/server/aws/credentials.ts \
apps/web/src/server/aws/ses.ts \
apps/web/src/server/aws/sns.ts \
.env.example \
.env.selfhost.example \
apps/web/.env.test.example ||true

Repository: usesend/useSend

Length of output: 41


🏁 Script executed:

# First, let's find the actual env schema/configuration file
fd -e js -e ts -e json apps/web/src/ | grep -i env | head -20

Repository: usesend/useSend

Length of output: 417


🏁 Script executed:

# Let's examine the credentials.ts file in full
cat -n apps/web/src/server/aws/credentials.ts

Repository: usesend/useSend

Length of output: 713


🏁 Script executed:

# Check the env.js or env schema structure
fd -type f -name "env*" apps/web/src/ | head -10

Repository: usesend/useSend

Length of output: 230


🏁 Script executed:

# Find env configuration files more carefully
find apps/web/src -name "env*" -type f | head -20

Repository: usesend/useSend

Length of output: 79


🏁 Script executed:

# Also search for where env is exported from
rg -l "export.*env" apps/web/src --type ts --type js | head -10

Repository: usesend/useSend

Length of output: 196


🏁 Script executed:

# Look for AWS configuration in existing code
rg "AWS_ACCESS_KEY_ID|AWS_SECRET_ACCESS_KEY" apps/web/src --type ts --type js -A 2 -B 2

Repository: usesend/useSend

Length of output: 2484


🏁 Script executed:

# Read the full env.js file
cat -n apps/web/src/env.js

Repository: usesend/useSend

Length of output: 7193


🏁 Script executed:

# Check AWS SDK documentation expectations for sessionToken# Look for any existing usage or patterns of sessionToken in the codebase
rg "sessionToken|session_token" apps/web --type ts --type js

Repository: usesend/useSend

Length of output: 41


🏁 Script executed:

# Check how AWS SDK is being used for SES and SNS
cat -n apps/web/src/server/aws/ses.ts | head -50

Repository: usesend/useSend

Length of output: 1938


🏁 Script executed:

# Look for any auth-related issues or comments in AWS files
rg "auth|sign|credential|temporary|session" apps/web/src/server/aws/ --type ts -i

Repository: usesend/useSend

Length of output: 781


🏁 Script executed:

# Check AWS SDK version/package being used
rg "@aws-sdk|aws-sdk" apps/web/package.json

Repository: usesend/useSend

Length of output: 265


Add AWS_SESSION_TOKEN support to credentials helper for temporary AWS credentials.

AWS SDK v3 requires sessionToken when using temporary credentials (from STS, IAM roles, or AssumeRole). The current implementation only handles accessKeyId and secretAccessKey, which works for long-lived IAM credentials but will fail with temporary credentials.

Add AWS_SESSION_TOKEN as an optional environment variable in env.js schema and runtimeEnv, then conditionally include it in the returned credentials object in credentials.ts. Update test setup and .env.example files as needed.

Suggested patch
 export function getAwsCredentialOptions() {
const hasKey = !!env.AWS_ACCESS_KEY_ID;
const hasSecret = !!env.AWS_SECRET_ACCESS_KEY;
+ const hasSessionToken = !!env.AWS_SESSION_TOKEN;
if (hasKey !== hasSecret) {
throw new Error(
"AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must both be set or both be omitted"
);
}
if (hasKey) {
return {
credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID!,
secretAccessKey: env.AWS_SECRET_ACCESS_KEY!,
+ ...(hasSessionToken ? { sessionToken: env.AWS_SESSION_TOKEN! } : {}),
},
};
}
return {};
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/web/src/server/aws/credentials.ts` around lines 4 - 19, The credentials
helper currently only returns accessKeyId and secretAccessKey, which breaks
temporary AWS creds; add support for AWS_SESSION_TOKEN by adding
AWS_SESSION_TOKEN to your env.js schema and runtimeEnv, then update the return
object in apps/web/src/server/aws/credentials.ts to conditionally include
sessionToken (e.g., when env.AWS_SESSION_TOKEN is present, add
credentials.sessionToken = env.AWS_SESSION_TOKEN) alongside accessKeyId and
secretAccessKey, and update test fixtures and .env.example to include an
optional AWS_SESSION_TOKEN entry so temporary credential flows are exercised.

@KMKoushik

Copy link
Copy Markdown
Member

merged with some changes in #401. ty

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feat: Avoid hardcoding AWS credentials & support standard AWS env variables

3 participants

@purva-8@KMKoushik
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
feat: support standard AWS env vars and default credential chain by purva-8 · Pull Request #395 · usesend/useSend · GitHub
Skip to content

feat: support standard AWS env vars and default credential chain - #395

Closed
purva-8 wants to merge 3 commits into
usesend:mainfrom
purva-8:feat/standard-aws-env-vars
Closed

feat: support standard AWS env vars and default credential chain#395
purva-8 wants to merge 3 commits into
usesend:mainfrom
purva-8:feat/standard-aws-env-vars

Conversation

@purva-8

@purva-8purva-8 commented May 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes#316

  • RenameAWS_ACCESS_KEYAWS_ACCESS_KEY_ID and AWS_SECRET_KEYAWS_SECRET_ACCESS_KEY to match the AWS standard naming convention used by the SDK, CLI, and IAM tooling
  • Make credentials optional: both vars are now z.string().optional() in the env schema
  • Default credential chain: when the vars are absent, the credentials object is omitted from SESv2Client, STSClient, and SNSClient — the AWS SDK automatically falls back to its default provider chain (IAM roles, ECS/EKS task roles, EC2 instance profiles, ~/.aws/credentials, etc.)
  • Backward compatibility: the runtimeEnv falls back to the old names (?? process.env.AWS_ACCESS_KEY) so existing deployments don't break without a config change

Files changed

FileChange
apps/web/src/env.jsRename schema keys, make optional, add backward-compat fallback
apps/web/src/server/aws/ses.tsConditionally pass credentials to SESv2Client / STSClient
apps/web/src/server/aws/sns.tsConditionally pass credentials to SNSClient
apps/web/src/test/setup/setup-env.tsUpdate test env keys
apps/web/.env.test.exampleUpdate example keys
.env.exampleUpdate example keys
.env.selfhost.exampleUpdate example keys, improve comment

Test plan

  • Existing deployments using the old AWS_ACCESS_KEY / AWS_SECRET_KEY names continue to work (backward-compat fallback)
  • Deployments using the new AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY names work
  • Deployments on ECS/EKS/EC2 with an IAM role and no credential env vars can boot and send email via the default provider chain
  • Unit tests pass (pnpm test)

Summary by cubic

Switches to AWS-standard env vars AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY and uses the AWS default credential chain when unset. Adds a shared credential helper that errors on partial configs; keeps backward compatibility and only passes credentials to SESv2, STS, and SNS when both vars are set.

  • New Features

    • Credentials are optional; SDK default chain is used when unset.
    • New getAwsCredentialOptions centralizes logic for SESv2Client, STSClient, and SNSClient.
    • Throws if only one of AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY is set.
  • Migration

    • Rename AWS_ACCESS_KEYAWS_ACCESS_KEY_ID and AWS_SECRET_KEYAWS_SECRET_ACCESS_KEY.
    • On IAM-role deployments, omit these vars to rely on the default chain.
    • Existing setups using old names keep working; migrate when convenient.

Written for commit 5c816be. Summary will update on new commits.

Summary by CodeRabbit

  • Chores
    • Renamed AWS credential environment variables from AWS_ACCESS_KEY/AWS_SECRET_KEY to AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY across examples and test configs.
    • Updated runtime validation to accept the new variables while falling back to the legacy names for compatibility.
    • Added credential-handling checks to ensure both new variables are set together (or omitted) to avoid misconfiguration.

Replace non-standard AWS_ACCESS_KEY / AWS_SECRET_KEY with the AWS-standard
AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY. The old names are kept as
fallbacks in the runtimeEnv for backward compatibility.
Both vars are now optional. When omitted, the credentials object is not
passed to SESv2Client, STSClient, or SNSClient — the AWS SDK then falls
back to its default provider chain (IAM roles, ECS task roles, instance
profiles, etc.), which is the recommended approach for cloud-native deployments.
Closesusesend#316
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
CopilotAI review requested due to automatic review settings May 2, 2026 12:24
@vercel

vercelBot commented May 2, 2026

Copy link
Copy Markdown

@purva-8 is attempting to deploy a commit to the kmkoushik's projects Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai

coderabbitaiBot commented May 2, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request updates AWS credential variable naming conventions across the codebase. Environment configuration files (.env.example, .env.selfhost.example, and apps/web/.env.test.example) are modified to use standard AWS naming (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY instead of AWS_ACCESS_KEY and AWS_SECRET_KEY). The environment schema in apps/web/src/env.js is updated to validate these new optional variables with fallback support for legacy names. AWS service clients in ses.ts and sns.ts are refactored to conditionally inject credentials using the new variable names. Test environment setup is similarly updated to populate the new credential variable names.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe title accurately summarizes the main changes: supporting standard AWS environment variables and enabling use of the default credential chain.
Linked Issues check✅ PassedAll coding requirements from issue #316 are met: standard AWS env vars are supported, credentials are optional, and the default credential chain can be used.
Out of Scope Changes check✅ PassedAll changes directly support the PR objectives of renaming AWS variables, making credentials optional, and maintaining backward compatibility.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 6/8 reviews remaining, refill in 9 minutes and 41 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the web app’s AWS credential handling to support standard AWS environment variable names and to allow the AWS SDK default credential provider chain when static credentials aren’t provided (fixing #316).

Changes:

  • Renames AWS_ACCESS_KEY / AWS_SECRET_KEY to AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY (with legacy fallback).
  • Makes AWS credential env vars optional and conditionally omits the credentials override for AWS SDK clients.
  • Updates test setup and example env files to reflect the new variable names.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
FileDescription
apps/web/src/env.jsUpdates env schema keys and adds legacy fallback in runtimeEnv.
apps/web/src/server/aws/ses.tsConditionally passes credentials to STSClient and SESv2Client.
apps/web/src/server/aws/sns.tsConditionally passes credentials to SNSClient.
apps/web/src/test/setup/setup-env.tsUpdates test env defaults to new AWS credential keys.
apps/web/.env.test.exampleUpdates example AWS credential keys for tests.
.env.exampleUpdates example AWS credential keys for local/dev.
.env.selfhost.exampleUpdates example keys and clarifies optional credential chain usage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadapps/web/src/env.js Outdated
Comment threadapps/web/src/env.js
Comment threadapps/web/src/server/aws/ses.ts Outdated
Comment threadapps/web/src/server/aws/sns.ts Outdated

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/web/src/server/aws/ses.ts (1)

33-35: ⚡ Quick win

Extract the repeated credential-options construction to a shared helper.

The same conditional spread appears three times: STS client (Line 33–35), SES client (Line 52–54), and the SNS client in sns.ts (Line 13–15). If the logic ever needs to add sessionToken or change the guard condition, all three sites must be updated in sync.

♻️ Proposed refactor

Add a shared helper (e.g. in apps/web/src/server/aws/credentials.ts):

import{env}from"~/env";exportfunctiongetAwsCredentialOptions(){if(env.AWS_ACCESS_KEY_ID&&env.AWS_SECRET_ACCESS_KEY){return{credentials: {accessKeyId: env.AWS_ACCESS_KEY_ID,secretAccessKey: env.AWS_SECRET_ACCESS_KEY,},};}return{};}

Then in ses.ts:

- ...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY- ? { credentials: { accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY } }- : {}),+ ...getAwsCredentialOptions(),

Apply the same replacement in the second occurrence in ses.ts and in sns.ts.

Also applies to: 52-54

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/web/src/server/aws/ses.ts` around lines 33 - 35, Extract the repeated
conditional credential spread into a shared helper (e.g.
getAwsCredentialOptions) that reads env.AWS_ACCESS_KEY_ID and
env.AWS_SECRET_ACCESS_KEY and returns either { credentials: { accessKeyId,
secretAccessKey } } or {}; then replace the inline conditional spread used when
constructing the STS client, SES client (the block containing
...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY ? { credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY }
} : {}) in ses.ts) and the SNS client in sns.ts with a call to
getAwsCredentialOptions(), ensuring the helper is exported from a common module
(e.g. credentials.ts) and imported where needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/web/src/server/aws/ses.ts`:
- Around line 33-35: Extract the repeated conditional credential spread into a
shared helper (e.g. getAwsCredentialOptions) that reads env.AWS_ACCESS_KEY_ID
and env.AWS_SECRET_ACCESS_KEY and returns either { credentials: { accessKeyId,
secretAccessKey } } or {}; then replace the inline conditional spread used when
constructing the STS client, SES client (the block containing
...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY ? { credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY }
} : {}) in ses.ts) and the SNS client in sns.ts with a call to
getAwsCredentialOptions(), ensuring the helper is exported from a common module
(e.g. credentials.ts) and imported where needed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 59ef1c51-59a4-4cf8-9644-0f3ad9c00c0f

📥 Commits

Reviewing files that changed from the base of the PR and between 964bbf9 and 83258bf.

📒 Files selected for processing (7)
  • .env.example
  • .env.selfhost.example
  • apps/web/.env.test.example
  • apps/web/src/env.js
  • apps/web/src/server/aws/ses.ts
  • apps/web/src/server/aws/sns.ts
  • apps/web/src/test/setup/setup-env.ts

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/web/src/env.js`:
- Around line 34-35: The environment schema currently allows AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY to be set independently which lets code in
apps/web/src/server/aws/ses.ts and apps/web/src/server/aws/sns.ts silently fall
back to the default provider when only one credential is present; update the zod
schema for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to validate they are
either both present or both absent (e.g., using a .refine or a custom validator)
so the app fails fast with a clear error when only one credential is provided,
and ensure any code that reads these vars (SES/SNS initialization) relies on
that validated pair rather than tolerating partial config.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d7aa3fb3-6172-4517-80bd-b5a93802008a

📥 Commits

Reviewing files that changed from the base of the PR and between 83258bf and 4277fb8.

📒 Files selected for processing (1)
  • apps/web/src/env.js

Comment threadapps/web/src/env.js
…al-config guard
- Move the credential spread logic into a single credentials.ts helper
so SESv2Client, STSClient, and SNSClient all share one implementation
- Throw a clear error if only one of AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY
is set, preventing silent fallback to the default provider chain with a
half-configured environment
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/web/src/server/aws/credentials.ts`:
- Around line 4-19: The credentials helper currently only returns accessKeyId
and secretAccessKey, which breaks temporary AWS creds; add support for
AWS_SESSION_TOKEN by adding AWS_SESSION_TOKEN to your env.js schema and
runtimeEnv, then update the return object in
apps/web/src/server/aws/credentials.ts to conditionally include sessionToken
(e.g., when env.AWS_SESSION_TOKEN is present, add credentials.sessionToken =
env.AWS_SESSION_TOKEN) alongside accessKeyId and secretAccessKey, and update
test fixtures and .env.example to include an optional AWS_SESSION_TOKEN entry so
temporary credential flows are exercised.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2d02e951-f64f-4566-99ee-986b878bc362

📥 Commits

Reviewing files that changed from the base of the PR and between 4277fb8 and 5c816be.

📒 Files selected for processing (3)
  • apps/web/src/server/aws/credentials.ts
  • apps/web/src/server/aws/ses.ts
  • apps/web/src/server/aws/sns.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/src/server/aws/sns.ts
  • apps/web/src/server/aws/ses.ts

Comment on lines +4 to +19
const hasKey = !!env.AWS_ACCESS_KEY_ID;
const hasSecret = !!env.AWS_SECRET_ACCESS_KEY;

if (hasKey !== hasSecret) {
throw new Error(
"AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must both be set or both be omitted"
);
}

if (hasKey) {
return {
credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID!,
secretAccessKey: env.AWS_SECRET_ACCESS_KEY!,
},
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash# Verify whether AWS_SESSION_TOKEN is modeled and propagated in current PR surface.# Expected: references in env schema/mapping + credentials helper + (optionally) env examples.
rg -n -C3 '\bAWS_SESSION_TOKEN\b' \
apps/web/src/env.js \
apps/web/src/server/aws/credentials.ts \
apps/web/src/server/aws/ses.ts \
apps/web/src/server/aws/sns.ts \
.env.example \
.env.selfhost.example \
apps/web/.env.test.example ||true

Repository: usesend/useSend

Length of output: 41


🏁 Script executed:

# First, let's find the actual env schema/configuration file
fd -e js -e ts -e json apps/web/src/ | grep -i env | head -20

Repository: usesend/useSend

Length of output: 417


🏁 Script executed:

# Let's examine the credentials.ts file in full
cat -n apps/web/src/server/aws/credentials.ts

Repository: usesend/useSend

Length of output: 713


🏁 Script executed:

# Check the env.js or env schema structure
fd -type f -name "env*" apps/web/src/ | head -10

Repository: usesend/useSend

Length of output: 230


🏁 Script executed:

# Find env configuration files more carefully
find apps/web/src -name "env*" -type f | head -20

Repository: usesend/useSend

Length of output: 79


🏁 Script executed:

# Also search for where env is exported from
rg -l "export.*env" apps/web/src --type ts --type js | head -10

Repository: usesend/useSend

Length of output: 196


🏁 Script executed:

# Look for AWS configuration in existing code
rg "AWS_ACCESS_KEY_ID|AWS_SECRET_ACCESS_KEY" apps/web/src --type ts --type js -A 2 -B 2

Repository: usesend/useSend

Length of output: 2484


🏁 Script executed:

# Read the full env.js file
cat -n apps/web/src/env.js

Repository: usesend/useSend

Length of output: 7193


🏁 Script executed:

# Check AWS SDK documentation expectations for sessionToken# Look for any existing usage or patterns of sessionToken in the codebase
rg "sessionToken|session_token" apps/web --type ts --type js

Repository: usesend/useSend

Length of output: 41


🏁 Script executed:

# Check how AWS SDK is being used for SES and SNS
cat -n apps/web/src/server/aws/ses.ts | head -50

Repository: usesend/useSend

Length of output: 1938


🏁 Script executed:

# Look for any auth-related issues or comments in AWS files
rg "auth|sign|credential|temporary|session" apps/web/src/server/aws/ --type ts -i

Repository: usesend/useSend

Length of output: 781


🏁 Script executed:

# Check AWS SDK version/package being used
rg "@aws-sdk|aws-sdk" apps/web/package.json

Repository: usesend/useSend

Length of output: 265


Add AWS_SESSION_TOKEN support to credentials helper for temporary AWS credentials.

AWS SDK v3 requires sessionToken when using temporary credentials (from STS, IAM roles, or AssumeRole). The current implementation only handles accessKeyId and secretAccessKey, which works for long-lived IAM credentials but will fail with temporary credentials.

Add AWS_SESSION_TOKEN as an optional environment variable in env.js schema and runtimeEnv, then conditionally include it in the returned credentials object in credentials.ts. Update test setup and .env.example files as needed.

Suggested patch
 export function getAwsCredentialOptions() {
const hasKey = !!env.AWS_ACCESS_KEY_ID;
const hasSecret = !!env.AWS_SECRET_ACCESS_KEY;
+ const hasSessionToken = !!env.AWS_SESSION_TOKEN;
if (hasKey !== hasSecret) {
throw new Error(
"AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must both be set or both be omitted"
);
}
if (hasKey) {
return {
credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID!,
secretAccessKey: env.AWS_SECRET_ACCESS_KEY!,
+ ...(hasSessionToken ? { sessionToken: env.AWS_SESSION_TOKEN! } : {}),
},
};
}
return {};
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/web/src/server/aws/credentials.ts` around lines 4 - 19, The credentials
helper currently only returns accessKeyId and secretAccessKey, which breaks
temporary AWS creds; add support for AWS_SESSION_TOKEN by adding
AWS_SESSION_TOKEN to your env.js schema and runtimeEnv, then update the return
object in apps/web/src/server/aws/credentials.ts to conditionally include
sessionToken (e.g., when env.AWS_SESSION_TOKEN is present, add
credentials.sessionToken = env.AWS_SESSION_TOKEN) alongside accessKeyId and
secretAccessKey, and update test fixtures and .env.example to include an
optional AWS_SESSION_TOKEN entry so temporary credential flows are exercised.

@KMKoushik

Copy link
Copy Markdown
Member

merged with some changes in #401. ty

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feat: Avoid hardcoding AWS credentials & support standard AWS env variables

3 participants

@purva-8@KMKoushik
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' feat: support standard AWS env vars and default credential chain by purva-8 · Pull Request #395 · usesend/useSend · GitHub
Skip to content

feat: support standard AWS env vars and default credential chain - #395

Closed
purva-8 wants to merge 3 commits into
usesend:mainfrom
purva-8:feat/standard-aws-env-vars
Closed

feat: support standard AWS env vars and default credential chain#395
purva-8 wants to merge 3 commits into
usesend:mainfrom
purva-8:feat/standard-aws-env-vars

Conversation

@purva-8

@purva-8purva-8 commented May 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes#316

  • RenameAWS_ACCESS_KEYAWS_ACCESS_KEY_ID and AWS_SECRET_KEYAWS_SECRET_ACCESS_KEY to match the AWS standard naming convention used by the SDK, CLI, and IAM tooling
  • Make credentials optional: both vars are now z.string().optional() in the env schema
  • Default credential chain: when the vars are absent, the credentials object is omitted from SESv2Client, STSClient, and SNSClient — the AWS SDK automatically falls back to its default provider chain (IAM roles, ECS/EKS task roles, EC2 instance profiles, ~/.aws/credentials, etc.)
  • Backward compatibility: the runtimeEnv falls back to the old names (?? process.env.AWS_ACCESS_KEY) so existing deployments don't break without a config change

Files changed

FileChange
apps/web/src/env.jsRename schema keys, make optional, add backward-compat fallback
apps/web/src/server/aws/ses.tsConditionally pass credentials to SESv2Client / STSClient
apps/web/src/server/aws/sns.tsConditionally pass credentials to SNSClient
apps/web/src/test/setup/setup-env.tsUpdate test env keys
apps/web/.env.test.exampleUpdate example keys
.env.exampleUpdate example keys
.env.selfhost.exampleUpdate example keys, improve comment

Test plan

  • Existing deployments using the old AWS_ACCESS_KEY / AWS_SECRET_KEY names continue to work (backward-compat fallback)
  • Deployments using the new AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY names work
  • Deployments on ECS/EKS/EC2 with an IAM role and no credential env vars can boot and send email via the default provider chain
  • Unit tests pass (pnpm test)

Summary by cubic

Switches to AWS-standard env vars AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY and uses the AWS default credential chain when unset. Adds a shared credential helper that errors on partial configs; keeps backward compatibility and only passes credentials to SESv2, STS, and SNS when both vars are set.

  • New Features

    • Credentials are optional; SDK default chain is used when unset.
    • New getAwsCredentialOptions centralizes logic for SESv2Client, STSClient, and SNSClient.
    • Throws if only one of AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY is set.
  • Migration

    • Rename AWS_ACCESS_KEYAWS_ACCESS_KEY_ID and AWS_SECRET_KEYAWS_SECRET_ACCESS_KEY.
    • On IAM-role deployments, omit these vars to rely on the default chain.
    • Existing setups using old names keep working; migrate when convenient.

Written for commit 5c816be. Summary will update on new commits.

Summary by CodeRabbit

  • Chores
    • Renamed AWS credential environment variables from AWS_ACCESS_KEY/AWS_SECRET_KEY to AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY across examples and test configs.
    • Updated runtime validation to accept the new variables while falling back to the legacy names for compatibility.
    • Added credential-handling checks to ensure both new variables are set together (or omitted) to avoid misconfiguration.

Replace non-standard AWS_ACCESS_KEY / AWS_SECRET_KEY with the AWS-standard
AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY. The old names are kept as
fallbacks in the runtimeEnv for backward compatibility.
Both vars are now optional. When omitted, the credentials object is not
passed to SESv2Client, STSClient, or SNSClient — the AWS SDK then falls
back to its default provider chain (IAM roles, ECS task roles, instance
profiles, etc.), which is the recommended approach for cloud-native deployments.
Closesusesend#316
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
CopilotAI review requested due to automatic review settings May 2, 2026 12:24
@vercel

vercelBot commented May 2, 2026

Copy link
Copy Markdown

@purva-8 is attempting to deploy a commit to the kmkoushik's projects Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai

coderabbitaiBot commented May 2, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request updates AWS credential variable naming conventions across the codebase. Environment configuration files (.env.example, .env.selfhost.example, and apps/web/.env.test.example) are modified to use standard AWS naming (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY instead of AWS_ACCESS_KEY and AWS_SECRET_KEY). The environment schema in apps/web/src/env.js is updated to validate these new optional variables with fallback support for legacy names. AWS service clients in ses.ts and sns.ts are refactored to conditionally inject credentials using the new variable names. Test environment setup is similarly updated to populate the new credential variable names.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe title accurately summarizes the main changes: supporting standard AWS environment variables and enabling use of the default credential chain.
Linked Issues check✅ PassedAll coding requirements from issue #316 are met: standard AWS env vars are supported, credentials are optional, and the default credential chain can be used.
Out of Scope Changes check✅ PassedAll changes directly support the PR objectives of renaming AWS variables, making credentials optional, and maintaining backward compatibility.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 6/8 reviews remaining, refill in 9 minutes and 41 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the web app’s AWS credential handling to support standard AWS environment variable names and to allow the AWS SDK default credential provider chain when static credentials aren’t provided (fixing #316).

Changes:

  • Renames AWS_ACCESS_KEY / AWS_SECRET_KEY to AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY (with legacy fallback).
  • Makes AWS credential env vars optional and conditionally omits the credentials override for AWS SDK clients.
  • Updates test setup and example env files to reflect the new variable names.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
FileDescription
apps/web/src/env.jsUpdates env schema keys and adds legacy fallback in runtimeEnv.
apps/web/src/server/aws/ses.tsConditionally passes credentials to STSClient and SESv2Client.
apps/web/src/server/aws/sns.tsConditionally passes credentials to SNSClient.
apps/web/src/test/setup/setup-env.tsUpdates test env defaults to new AWS credential keys.
apps/web/.env.test.exampleUpdates example AWS credential keys for tests.
.env.exampleUpdates example AWS credential keys for local/dev.
.env.selfhost.exampleUpdates example keys and clarifies optional credential chain usage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadapps/web/src/env.js Outdated
Comment threadapps/web/src/env.js
Comment threadapps/web/src/server/aws/ses.ts Outdated
Comment threadapps/web/src/server/aws/sns.ts Outdated

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/web/src/server/aws/ses.ts (1)

33-35: ⚡ Quick win

Extract the repeated credential-options construction to a shared helper.

The same conditional spread appears three times: STS client (Line 33–35), SES client (Line 52–54), and the SNS client in sns.ts (Line 13–15). If the logic ever needs to add sessionToken or change the guard condition, all three sites must be updated in sync.

♻️ Proposed refactor

Add a shared helper (e.g. in apps/web/src/server/aws/credentials.ts):

import{env}from"~/env";exportfunctiongetAwsCredentialOptions(){if(env.AWS_ACCESS_KEY_ID&&env.AWS_SECRET_ACCESS_KEY){return{credentials: {accessKeyId: env.AWS_ACCESS_KEY_ID,secretAccessKey: env.AWS_SECRET_ACCESS_KEY,},};}return{};}

Then in ses.ts:

- ...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY- ? { credentials: { accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY } }- : {}),+ ...getAwsCredentialOptions(),

Apply the same replacement in the second occurrence in ses.ts and in sns.ts.

Also applies to: 52-54

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/web/src/server/aws/ses.ts` around lines 33 - 35, Extract the repeated
conditional credential spread into a shared helper (e.g.
getAwsCredentialOptions) that reads env.AWS_ACCESS_KEY_ID and
env.AWS_SECRET_ACCESS_KEY and returns either { credentials: { accessKeyId,
secretAccessKey } } or {}; then replace the inline conditional spread used when
constructing the STS client, SES client (the block containing
...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY ? { credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY }
} : {}) in ses.ts) and the SNS client in sns.ts with a call to
getAwsCredentialOptions(), ensuring the helper is exported from a common module
(e.g. credentials.ts) and imported where needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/web/src/server/aws/ses.ts`:
- Around line 33-35: Extract the repeated conditional credential spread into a
shared helper (e.g. getAwsCredentialOptions) that reads env.AWS_ACCESS_KEY_ID
and env.AWS_SECRET_ACCESS_KEY and returns either { credentials: { accessKeyId,
secretAccessKey } } or {}; then replace the inline conditional spread used when
constructing the STS client, SES client (the block containing
...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY ? { credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY }
} : {}) in ses.ts) and the SNS client in sns.ts with a call to
getAwsCredentialOptions(), ensuring the helper is exported from a common module
(e.g. credentials.ts) and imported where needed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 59ef1c51-59a4-4cf8-9644-0f3ad9c00c0f

📥 Commits

Reviewing files that changed from the base of the PR and between 964bbf9 and 83258bf.

📒 Files selected for processing (7)
  • .env.example
  • .env.selfhost.example
  • apps/web/.env.test.example
  • apps/web/src/env.js
  • apps/web/src/server/aws/ses.ts
  • apps/web/src/server/aws/sns.ts
  • apps/web/src/test/setup/setup-env.ts

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/web/src/env.js`:
- Around line 34-35: The environment schema currently allows AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY to be set independently which lets code in
apps/web/src/server/aws/ses.ts and apps/web/src/server/aws/sns.ts silently fall
back to the default provider when only one credential is present; update the zod
schema for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to validate they are
either both present or both absent (e.g., using a .refine or a custom validator)
so the app fails fast with a clear error when only one credential is provided,
and ensure any code that reads these vars (SES/SNS initialization) relies on
that validated pair rather than tolerating partial config.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d7aa3fb3-6172-4517-80bd-b5a93802008a

📥 Commits

Reviewing files that changed from the base of the PR and between 83258bf and 4277fb8.

📒 Files selected for processing (1)
  • apps/web/src/env.js

Comment threadapps/web/src/env.js
…al-config guard
- Move the credential spread logic into a single credentials.ts helper
so SESv2Client, STSClient, and SNSClient all share one implementation
- Throw a clear error if only one of AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY
is set, preventing silent fallback to the default provider chain with a
half-configured environment
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/web/src/server/aws/credentials.ts`:
- Around line 4-19: The credentials helper currently only returns accessKeyId
and secretAccessKey, which breaks temporary AWS creds; add support for
AWS_SESSION_TOKEN by adding AWS_SESSION_TOKEN to your env.js schema and
runtimeEnv, then update the return object in
apps/web/src/server/aws/credentials.ts to conditionally include sessionToken
(e.g., when env.AWS_SESSION_TOKEN is present, add credentials.sessionToken =
env.AWS_SESSION_TOKEN) alongside accessKeyId and secretAccessKey, and update
test fixtures and .env.example to include an optional AWS_SESSION_TOKEN entry so
temporary credential flows are exercised.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2d02e951-f64f-4566-99ee-986b878bc362

📥 Commits

Reviewing files that changed from the base of the PR and between 4277fb8 and 5c816be.

📒 Files selected for processing (3)
  • apps/web/src/server/aws/credentials.ts
  • apps/web/src/server/aws/ses.ts
  • apps/web/src/server/aws/sns.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/src/server/aws/sns.ts
  • apps/web/src/server/aws/ses.ts

Comment on lines +4 to +19
const hasKey = !!env.AWS_ACCESS_KEY_ID;
const hasSecret = !!env.AWS_SECRET_ACCESS_KEY;

if (hasKey !== hasSecret) {
throw new Error(
"AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must both be set or both be omitted"
);
}

if (hasKey) {
return {
credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID!,
secretAccessKey: env.AWS_SECRET_ACCESS_KEY!,
},
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash# Verify whether AWS_SESSION_TOKEN is modeled and propagated in current PR surface.# Expected: references in env schema/mapping + credentials helper + (optionally) env examples.
rg -n -C3 '\bAWS_SESSION_TOKEN\b' \
apps/web/src/env.js \
apps/web/src/server/aws/credentials.ts \
apps/web/src/server/aws/ses.ts \
apps/web/src/server/aws/sns.ts \
.env.example \
.env.selfhost.example \
apps/web/.env.test.example ||true

Repository: usesend/useSend

Length of output: 41


🏁 Script executed:

# First, let's find the actual env schema/configuration file
fd -e js -e ts -e json apps/web/src/ | grep -i env | head -20

Repository: usesend/useSend

Length of output: 417


🏁 Script executed:

# Let's examine the credentials.ts file in full
cat -n apps/web/src/server/aws/credentials.ts

Repository: usesend/useSend

Length of output: 713


🏁 Script executed:

# Check the env.js or env schema structure
fd -type f -name "env*" apps/web/src/ | head -10

Repository: usesend/useSend

Length of output: 230


🏁 Script executed:

# Find env configuration files more carefully
find apps/web/src -name "env*" -type f | head -20

Repository: usesend/useSend

Length of output: 79


🏁 Script executed:

# Also search for where env is exported from
rg -l "export.*env" apps/web/src --type ts --type js | head -10

Repository: usesend/useSend

Length of output: 196


🏁 Script executed:

# Look for AWS configuration in existing code
rg "AWS_ACCESS_KEY_ID|AWS_SECRET_ACCESS_KEY" apps/web/src --type ts --type js -A 2 -B 2

Repository: usesend/useSend

Length of output: 2484


🏁 Script executed:

# Read the full env.js file
cat -n apps/web/src/env.js

Repository: usesend/useSend

Length of output: 7193


🏁 Script executed:

# Check AWS SDK documentation expectations for sessionToken# Look for any existing usage or patterns of sessionToken in the codebase
rg "sessionToken|session_token" apps/web --type ts --type js

Repository: usesend/useSend

Length of output: 41


🏁 Script executed:

# Check how AWS SDK is being used for SES and SNS
cat -n apps/web/src/server/aws/ses.ts | head -50

Repository: usesend/useSend

Length of output: 1938


🏁 Script executed:

# Look for any auth-related issues or comments in AWS files
rg "auth|sign|credential|temporary|session" apps/web/src/server/aws/ --type ts -i

Repository: usesend/useSend

Length of output: 781


🏁 Script executed:

# Check AWS SDK version/package being used
rg "@aws-sdk|aws-sdk" apps/web/package.json

Repository: usesend/useSend

Length of output: 265


Add AWS_SESSION_TOKEN support to credentials helper for temporary AWS credentials.

AWS SDK v3 requires sessionToken when using temporary credentials (from STS, IAM roles, or AssumeRole). The current implementation only handles accessKeyId and secretAccessKey, which works for long-lived IAM credentials but will fail with temporary credentials.

Add AWS_SESSION_TOKEN as an optional environment variable in env.js schema and runtimeEnv, then conditionally include it in the returned credentials object in credentials.ts. Update test setup and .env.example files as needed.

Suggested patch
 export function getAwsCredentialOptions() {
const hasKey = !!env.AWS_ACCESS_KEY_ID;
const hasSecret = !!env.AWS_SECRET_ACCESS_KEY;
+ const hasSessionToken = !!env.AWS_SESSION_TOKEN;
if (hasKey !== hasSecret) {
throw new Error(
"AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must both be set or both be omitted"
);
}
if (hasKey) {
return {
credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID!,
secretAccessKey: env.AWS_SECRET_ACCESS_KEY!,
+ ...(hasSessionToken ? { sessionToken: env.AWS_SESSION_TOKEN! } : {}),
},
};
}
return {};
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/web/src/server/aws/credentials.ts` around lines 4 - 19, The credentials
helper currently only returns accessKeyId and secretAccessKey, which breaks
temporary AWS creds; add support for AWS_SESSION_TOKEN by adding
AWS_SESSION_TOKEN to your env.js schema and runtimeEnv, then update the return
object in apps/web/src/server/aws/credentials.ts to conditionally include
sessionToken (e.g., when env.AWS_SESSION_TOKEN is present, add
credentials.sessionToken = env.AWS_SESSION_TOKEN) alongside accessKeyId and
secretAccessKey, and update test fixtures and .env.example to include an
optional AWS_SESSION_TOKEN entry so temporary credential flows are exercised.

@KMKoushik

Copy link
Copy Markdown
Member

merged with some changes in #401. ty

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feat: Avoid hardcoding AWS credentials & support standard AWS env variables

3 participants

@purva-8@KMKoushik
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' feat: support standard AWS env vars and default credential chain by purva-8 · Pull Request #395 · usesend/useSend · GitHub
Skip to content

feat: support standard AWS env vars and default credential chain - #395

Closed
purva-8 wants to merge 3 commits into
usesend:mainfrom
purva-8:feat/standard-aws-env-vars
Closed

feat: support standard AWS env vars and default credential chain#395
purva-8 wants to merge 3 commits into
usesend:mainfrom
purva-8:feat/standard-aws-env-vars

Conversation

@purva-8

@purva-8purva-8 commented May 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes#316

  • RenameAWS_ACCESS_KEYAWS_ACCESS_KEY_ID and AWS_SECRET_KEYAWS_SECRET_ACCESS_KEY to match the AWS standard naming convention used by the SDK, CLI, and IAM tooling
  • Make credentials optional: both vars are now z.string().optional() in the env schema
  • Default credential chain: when the vars are absent, the credentials object is omitted from SESv2Client, STSClient, and SNSClient — the AWS SDK automatically falls back to its default provider chain (IAM roles, ECS/EKS task roles, EC2 instance profiles, ~/.aws/credentials, etc.)
  • Backward compatibility: the runtimeEnv falls back to the old names (?? process.env.AWS_ACCESS_KEY) so existing deployments don't break without a config change

Files changed

FileChange
apps/web/src/env.jsRename schema keys, make optional, add backward-compat fallback
apps/web/src/server/aws/ses.tsConditionally pass credentials to SESv2Client / STSClient
apps/web/src/server/aws/sns.tsConditionally pass credentials to SNSClient
apps/web/src/test/setup/setup-env.tsUpdate test env keys
apps/web/.env.test.exampleUpdate example keys
.env.exampleUpdate example keys
.env.selfhost.exampleUpdate example keys, improve comment

Test plan

  • Existing deployments using the old AWS_ACCESS_KEY / AWS_SECRET_KEY names continue to work (backward-compat fallback)
  • Deployments using the new AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY names work
  • Deployments on ECS/EKS/EC2 with an IAM role and no credential env vars can boot and send email via the default provider chain
  • Unit tests pass (pnpm test)

Summary by cubic

Switches to AWS-standard env vars AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY and uses the AWS default credential chain when unset. Adds a shared credential helper that errors on partial configs; keeps backward compatibility and only passes credentials to SESv2, STS, and SNS when both vars are set.

  • New Features

    • Credentials are optional; SDK default chain is used when unset.
    • New getAwsCredentialOptions centralizes logic for SESv2Client, STSClient, and SNSClient.
    • Throws if only one of AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY is set.
  • Migration

    • Rename AWS_ACCESS_KEYAWS_ACCESS_KEY_ID and AWS_SECRET_KEYAWS_SECRET_ACCESS_KEY.
    • On IAM-role deployments, omit these vars to rely on the default chain.
    • Existing setups using old names keep working; migrate when convenient.

Written for commit 5c816be. Summary will update on new commits.

Summary by CodeRabbit

  • Chores
    • Renamed AWS credential environment variables from AWS_ACCESS_KEY/AWS_SECRET_KEY to AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY across examples and test configs.
    • Updated runtime validation to accept the new variables while falling back to the legacy names for compatibility.
    • Added credential-handling checks to ensure both new variables are set together (or omitted) to avoid misconfiguration.

Replace non-standard AWS_ACCESS_KEY / AWS_SECRET_KEY with the AWS-standard
AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY. The old names are kept as
fallbacks in the runtimeEnv for backward compatibility.
Both vars are now optional. When omitted, the credentials object is not
passed to SESv2Client, STSClient, or SNSClient — the AWS SDK then falls
back to its default provider chain (IAM roles, ECS task roles, instance
profiles, etc.), which is the recommended approach for cloud-native deployments.
Closesusesend#316
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
CopilotAI review requested due to automatic review settings May 2, 2026 12:24
@vercel

vercelBot commented May 2, 2026

Copy link
Copy Markdown

@purva-8 is attempting to deploy a commit to the kmkoushik's projects Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai

coderabbitaiBot commented May 2, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request updates AWS credential variable naming conventions across the codebase. Environment configuration files (.env.example, .env.selfhost.example, and apps/web/.env.test.example) are modified to use standard AWS naming (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY instead of AWS_ACCESS_KEY and AWS_SECRET_KEY). The environment schema in apps/web/src/env.js is updated to validate these new optional variables with fallback support for legacy names. AWS service clients in ses.ts and sns.ts are refactored to conditionally inject credentials using the new variable names. Test environment setup is similarly updated to populate the new credential variable names.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe title accurately summarizes the main changes: supporting standard AWS environment variables and enabling use of the default credential chain.
Linked Issues check✅ PassedAll coding requirements from issue #316 are met: standard AWS env vars are supported, credentials are optional, and the default credential chain can be used.
Out of Scope Changes check✅ PassedAll changes directly support the PR objectives of renaming AWS variables, making credentials optional, and maintaining backward compatibility.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 6/8 reviews remaining, refill in 9 minutes and 41 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the web app’s AWS credential handling to support standard AWS environment variable names and to allow the AWS SDK default credential provider chain when static credentials aren’t provided (fixing #316).

Changes:

  • Renames AWS_ACCESS_KEY / AWS_SECRET_KEY to AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY (with legacy fallback).
  • Makes AWS credential env vars optional and conditionally omits the credentials override for AWS SDK clients.
  • Updates test setup and example env files to reflect the new variable names.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
FileDescription
apps/web/src/env.jsUpdates env schema keys and adds legacy fallback in runtimeEnv.
apps/web/src/server/aws/ses.tsConditionally passes credentials to STSClient and SESv2Client.
apps/web/src/server/aws/sns.tsConditionally passes credentials to SNSClient.
apps/web/src/test/setup/setup-env.tsUpdates test env defaults to new AWS credential keys.
apps/web/.env.test.exampleUpdates example AWS credential keys for tests.
.env.exampleUpdates example AWS credential keys for local/dev.
.env.selfhost.exampleUpdates example keys and clarifies optional credential chain usage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadapps/web/src/env.js Outdated
Comment threadapps/web/src/env.js
Comment threadapps/web/src/server/aws/ses.ts Outdated
Comment threadapps/web/src/server/aws/sns.ts Outdated

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/web/src/server/aws/ses.ts (1)

33-35: ⚡ Quick win

Extract the repeated credential-options construction to a shared helper.

The same conditional spread appears three times: STS client (Line 33–35), SES client (Line 52–54), and the SNS client in sns.ts (Line 13–15). If the logic ever needs to add sessionToken or change the guard condition, all three sites must be updated in sync.

♻️ Proposed refactor

Add a shared helper (e.g. in apps/web/src/server/aws/credentials.ts):

import{env}from"~/env";exportfunctiongetAwsCredentialOptions(){if(env.AWS_ACCESS_KEY_ID&&env.AWS_SECRET_ACCESS_KEY){return{credentials: {accessKeyId: env.AWS_ACCESS_KEY_ID,secretAccessKey: env.AWS_SECRET_ACCESS_KEY,},};}return{};}

Then in ses.ts:

- ...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY- ? { credentials: { accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY } }- : {}),+ ...getAwsCredentialOptions(),

Apply the same replacement in the second occurrence in ses.ts and in sns.ts.

Also applies to: 52-54

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/web/src/server/aws/ses.ts` around lines 33 - 35, Extract the repeated
conditional credential spread into a shared helper (e.g.
getAwsCredentialOptions) that reads env.AWS_ACCESS_KEY_ID and
env.AWS_SECRET_ACCESS_KEY and returns either { credentials: { accessKeyId,
secretAccessKey } } or {}; then replace the inline conditional spread used when
constructing the STS client, SES client (the block containing
...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY ? { credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY }
} : {}) in ses.ts) and the SNS client in sns.ts with a call to
getAwsCredentialOptions(), ensuring the helper is exported from a common module
(e.g. credentials.ts) and imported where needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/web/src/server/aws/ses.ts`:
- Around line 33-35: Extract the repeated conditional credential spread into a
shared helper (e.g. getAwsCredentialOptions) that reads env.AWS_ACCESS_KEY_ID
and env.AWS_SECRET_ACCESS_KEY and returns either { credentials: { accessKeyId,
secretAccessKey } } or {}; then replace the inline conditional spread used when
constructing the STS client, SES client (the block containing
...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY ? { credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY }
} : {}) in ses.ts) and the SNS client in sns.ts with a call to
getAwsCredentialOptions(), ensuring the helper is exported from a common module
(e.g. credentials.ts) and imported where needed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 59ef1c51-59a4-4cf8-9644-0f3ad9c00c0f

📥 Commits

Reviewing files that changed from the base of the PR and between 964bbf9 and 83258bf.

📒 Files selected for processing (7)
  • .env.example
  • .env.selfhost.example
  • apps/web/.env.test.example
  • apps/web/src/env.js
  • apps/web/src/server/aws/ses.ts
  • apps/web/src/server/aws/sns.ts
  • apps/web/src/test/setup/setup-env.ts

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/web/src/env.js`:
- Around line 34-35: The environment schema currently allows AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY to be set independently which lets code in
apps/web/src/server/aws/ses.ts and apps/web/src/server/aws/sns.ts silently fall
back to the default provider when only one credential is present; update the zod
schema for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to validate they are
either both present or both absent (e.g., using a .refine or a custom validator)
so the app fails fast with a clear error when only one credential is provided,
and ensure any code that reads these vars (SES/SNS initialization) relies on
that validated pair rather than tolerating partial config.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d7aa3fb3-6172-4517-80bd-b5a93802008a

📥 Commits

Reviewing files that changed from the base of the PR and between 83258bf and 4277fb8.

📒 Files selected for processing (1)
  • apps/web/src/env.js

Comment threadapps/web/src/env.js
…al-config guard
- Move the credential spread logic into a single credentials.ts helper
so SESv2Client, STSClient, and SNSClient all share one implementation
- Throw a clear error if only one of AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY
is set, preventing silent fallback to the default provider chain with a
half-configured environment
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/web/src/server/aws/credentials.ts`:
- Around line 4-19: The credentials helper currently only returns accessKeyId
and secretAccessKey, which breaks temporary AWS creds; add support for
AWS_SESSION_TOKEN by adding AWS_SESSION_TOKEN to your env.js schema and
runtimeEnv, then update the return object in
apps/web/src/server/aws/credentials.ts to conditionally include sessionToken
(e.g., when env.AWS_SESSION_TOKEN is present, add credentials.sessionToken =
env.AWS_SESSION_TOKEN) alongside accessKeyId and secretAccessKey, and update
test fixtures and .env.example to include an optional AWS_SESSION_TOKEN entry so
temporary credential flows are exercised.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2d02e951-f64f-4566-99ee-986b878bc362

📥 Commits

Reviewing files that changed from the base of the PR and between 4277fb8 and 5c816be.

📒 Files selected for processing (3)
  • apps/web/src/server/aws/credentials.ts
  • apps/web/src/server/aws/ses.ts
  • apps/web/src/server/aws/sns.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/src/server/aws/sns.ts
  • apps/web/src/server/aws/ses.ts

Comment on lines +4 to +19
const hasKey = !!env.AWS_ACCESS_KEY_ID;
const hasSecret = !!env.AWS_SECRET_ACCESS_KEY;

if (hasKey !== hasSecret) {
throw new Error(
"AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must both be set or both be omitted"
);
}

if (hasKey) {
return {
credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID!,
secretAccessKey: env.AWS_SECRET_ACCESS_KEY!,
},
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash# Verify whether AWS_SESSION_TOKEN is modeled and propagated in current PR surface.# Expected: references in env schema/mapping + credentials helper + (optionally) env examples.
rg -n -C3 '\bAWS_SESSION_TOKEN\b' \
apps/web/src/env.js \
apps/web/src/server/aws/credentials.ts \
apps/web/src/server/aws/ses.ts \
apps/web/src/server/aws/sns.ts \
.env.example \
.env.selfhost.example \
apps/web/.env.test.example ||true

Repository: usesend/useSend

Length of output: 41


🏁 Script executed:

# First, let's find the actual env schema/configuration file
fd -e js -e ts -e json apps/web/src/ | grep -i env | head -20

Repository: usesend/useSend

Length of output: 417


🏁 Script executed:

# Let's examine the credentials.ts file in full
cat -n apps/web/src/server/aws/credentials.ts

Repository: usesend/useSend

Length of output: 713


🏁 Script executed:

# Check the env.js or env schema structure
fd -type f -name "env*" apps/web/src/ | head -10

Repository: usesend/useSend

Length of output: 230


🏁 Script executed:

# Find env configuration files more carefully
find apps/web/src -name "env*" -type f | head -20

Repository: usesend/useSend

Length of output: 79


🏁 Script executed:

# Also search for where env is exported from
rg -l "export.*env" apps/web/src --type ts --type js | head -10

Repository: usesend/useSend

Length of output: 196


🏁 Script executed:

# Look for AWS configuration in existing code
rg "AWS_ACCESS_KEY_ID|AWS_SECRET_ACCESS_KEY" apps/web/src --type ts --type js -A 2 -B 2

Repository: usesend/useSend

Length of output: 2484


🏁 Script executed:

# Read the full env.js file
cat -n apps/web/src/env.js

Repository: usesend/useSend

Length of output: 7193


🏁 Script executed:

# Check AWS SDK documentation expectations for sessionToken# Look for any existing usage or patterns of sessionToken in the codebase
rg "sessionToken|session_token" apps/web --type ts --type js

Repository: usesend/useSend

Length of output: 41


🏁 Script executed:

# Check how AWS SDK is being used for SES and SNS
cat -n apps/web/src/server/aws/ses.ts | head -50

Repository: usesend/useSend

Length of output: 1938


🏁 Script executed:

# Look for any auth-related issues or comments in AWS files
rg "auth|sign|credential|temporary|session" apps/web/src/server/aws/ --type ts -i

Repository: usesend/useSend

Length of output: 781


🏁 Script executed:

# Check AWS SDK version/package being used
rg "@aws-sdk|aws-sdk" apps/web/package.json

Repository: usesend/useSend

Length of output: 265


Add AWS_SESSION_TOKEN support to credentials helper for temporary AWS credentials.

AWS SDK v3 requires sessionToken when using temporary credentials (from STS, IAM roles, or AssumeRole). The current implementation only handles accessKeyId and secretAccessKey, which works for long-lived IAM credentials but will fail with temporary credentials.

Add AWS_SESSION_TOKEN as an optional environment variable in env.js schema and runtimeEnv, then conditionally include it in the returned credentials object in credentials.ts. Update test setup and .env.example files as needed.

Suggested patch
 export function getAwsCredentialOptions() {
const hasKey = !!env.AWS_ACCESS_KEY_ID;
const hasSecret = !!env.AWS_SECRET_ACCESS_KEY;
+ const hasSessionToken = !!env.AWS_SESSION_TOKEN;
if (hasKey !== hasSecret) {
throw new Error(
"AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must both be set or both be omitted"
);
}
if (hasKey) {
return {
credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID!,
secretAccessKey: env.AWS_SECRET_ACCESS_KEY!,
+ ...(hasSessionToken ? { sessionToken: env.AWS_SESSION_TOKEN! } : {}),
},
};
}
return {};
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/web/src/server/aws/credentials.ts` around lines 4 - 19, The credentials
helper currently only returns accessKeyId and secretAccessKey, which breaks
temporary AWS creds; add support for AWS_SESSION_TOKEN by adding
AWS_SESSION_TOKEN to your env.js schema and runtimeEnv, then update the return
object in apps/web/src/server/aws/credentials.ts to conditionally include
sessionToken (e.g., when env.AWS_SESSION_TOKEN is present, add
credentials.sessionToken = env.AWS_SESSION_TOKEN) alongside accessKeyId and
secretAccessKey, and update test fixtures and .env.example to include an
optional AWS_SESSION_TOKEN entry so temporary credential flows are exercised.

@KMKoushik

Copy link
Copy Markdown
Member

merged with some changes in #401. ty

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feat: Avoid hardcoding AWS credentials & support standard AWS env variables

3 participants

@purva-8@KMKoushik
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' feat: support standard AWS env vars and default credential chain by purva-8 · Pull Request #395 · usesend/useSend · GitHub
Skip to content

feat: support standard AWS env vars and default credential chain - #395

Closed
purva-8 wants to merge 3 commits into
usesend:mainfrom
purva-8:feat/standard-aws-env-vars
Closed

feat: support standard AWS env vars and default credential chain#395
purva-8 wants to merge 3 commits into
usesend:mainfrom
purva-8:feat/standard-aws-env-vars

Conversation

@purva-8

@purva-8purva-8 commented May 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes#316

  • RenameAWS_ACCESS_KEYAWS_ACCESS_KEY_ID and AWS_SECRET_KEYAWS_SECRET_ACCESS_KEY to match the AWS standard naming convention used by the SDK, CLI, and IAM tooling
  • Make credentials optional: both vars are now z.string().optional() in the env schema
  • Default credential chain: when the vars are absent, the credentials object is omitted from SESv2Client, STSClient, and SNSClient — the AWS SDK automatically falls back to its default provider chain (IAM roles, ECS/EKS task roles, EC2 instance profiles, ~/.aws/credentials, etc.)
  • Backward compatibility: the runtimeEnv falls back to the old names (?? process.env.AWS_ACCESS_KEY) so existing deployments don't break without a config change

Files changed

FileChange
apps/web/src/env.jsRename schema keys, make optional, add backward-compat fallback
apps/web/src/server/aws/ses.tsConditionally pass credentials to SESv2Client / STSClient
apps/web/src/server/aws/sns.tsConditionally pass credentials to SNSClient
apps/web/src/test/setup/setup-env.tsUpdate test env keys
apps/web/.env.test.exampleUpdate example keys
.env.exampleUpdate example keys
.env.selfhost.exampleUpdate example keys, improve comment

Test plan

  • Existing deployments using the old AWS_ACCESS_KEY / AWS_SECRET_KEY names continue to work (backward-compat fallback)
  • Deployments using the new AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY names work
  • Deployments on ECS/EKS/EC2 with an IAM role and no credential env vars can boot and send email via the default provider chain
  • Unit tests pass (pnpm test)

Summary by cubic

Switches to AWS-standard env vars AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY and uses the AWS default credential chain when unset. Adds a shared credential helper that errors on partial configs; keeps backward compatibility and only passes credentials to SESv2, STS, and SNS when both vars are set.

  • New Features

    • Credentials are optional; SDK default chain is used when unset.
    • New getAwsCredentialOptions centralizes logic for SESv2Client, STSClient, and SNSClient.
    • Throws if only one of AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY is set.
  • Migration

    • Rename AWS_ACCESS_KEYAWS_ACCESS_KEY_ID and AWS_SECRET_KEYAWS_SECRET_ACCESS_KEY.
    • On IAM-role deployments, omit these vars to rely on the default chain.
    • Existing setups using old names keep working; migrate when convenient.

Written for commit 5c816be. Summary will update on new commits.

Summary by CodeRabbit

  • Chores
    • Renamed AWS credential environment variables from AWS_ACCESS_KEY/AWS_SECRET_KEY to AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY across examples and test configs.
    • Updated runtime validation to accept the new variables while falling back to the legacy names for compatibility.
    • Added credential-handling checks to ensure both new variables are set together (or omitted) to avoid misconfiguration.

Replace non-standard AWS_ACCESS_KEY / AWS_SECRET_KEY with the AWS-standard
AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY. The old names are kept as
fallbacks in the runtimeEnv for backward compatibility.
Both vars are now optional. When omitted, the credentials object is not
passed to SESv2Client, STSClient, or SNSClient — the AWS SDK then falls
back to its default provider chain (IAM roles, ECS task roles, instance
profiles, etc.), which is the recommended approach for cloud-native deployments.
Closesusesend#316
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
CopilotAI review requested due to automatic review settings May 2, 2026 12:24
@vercel

vercelBot commented May 2, 2026

Copy link
Copy Markdown

@purva-8 is attempting to deploy a commit to the kmkoushik's projects Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai

coderabbitaiBot commented May 2, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request updates AWS credential variable naming conventions across the codebase. Environment configuration files (.env.example, .env.selfhost.example, and apps/web/.env.test.example) are modified to use standard AWS naming (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY instead of AWS_ACCESS_KEY and AWS_SECRET_KEY). The environment schema in apps/web/src/env.js is updated to validate these new optional variables with fallback support for legacy names. AWS service clients in ses.ts and sns.ts are refactored to conditionally inject credentials using the new variable names. Test environment setup is similarly updated to populate the new credential variable names.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe title accurately summarizes the main changes: supporting standard AWS environment variables and enabling use of the default credential chain.
Linked Issues check✅ PassedAll coding requirements from issue #316 are met: standard AWS env vars are supported, credentials are optional, and the default credential chain can be used.
Out of Scope Changes check✅ PassedAll changes directly support the PR objectives of renaming AWS variables, making credentials optional, and maintaining backward compatibility.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 6/8 reviews remaining, refill in 9 minutes and 41 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the web app’s AWS credential handling to support standard AWS environment variable names and to allow the AWS SDK default credential provider chain when static credentials aren’t provided (fixing #316).

Changes:

  • Renames AWS_ACCESS_KEY / AWS_SECRET_KEY to AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY (with legacy fallback).
  • Makes AWS credential env vars optional and conditionally omits the credentials override for AWS SDK clients.
  • Updates test setup and example env files to reflect the new variable names.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
FileDescription
apps/web/src/env.jsUpdates env schema keys and adds legacy fallback in runtimeEnv.
apps/web/src/server/aws/ses.tsConditionally passes credentials to STSClient and SESv2Client.
apps/web/src/server/aws/sns.tsConditionally passes credentials to SNSClient.
apps/web/src/test/setup/setup-env.tsUpdates test env defaults to new AWS credential keys.
apps/web/.env.test.exampleUpdates example AWS credential keys for tests.
.env.exampleUpdates example AWS credential keys for local/dev.
.env.selfhost.exampleUpdates example keys and clarifies optional credential chain usage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadapps/web/src/env.js Outdated
Comment threadapps/web/src/env.js
Comment threadapps/web/src/server/aws/ses.ts Outdated
Comment threadapps/web/src/server/aws/sns.ts Outdated

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/web/src/server/aws/ses.ts (1)

33-35: ⚡ Quick win

Extract the repeated credential-options construction to a shared helper.

The same conditional spread appears three times: STS client (Line 33–35), SES client (Line 52–54), and the SNS client in sns.ts (Line 13–15). If the logic ever needs to add sessionToken or change the guard condition, all three sites must be updated in sync.

♻️ Proposed refactor

Add a shared helper (e.g. in apps/web/src/server/aws/credentials.ts):

import{env}from"~/env";exportfunctiongetAwsCredentialOptions(){if(env.AWS_ACCESS_KEY_ID&&env.AWS_SECRET_ACCESS_KEY){return{credentials: {accessKeyId: env.AWS_ACCESS_KEY_ID,secretAccessKey: env.AWS_SECRET_ACCESS_KEY,},};}return{};}

Then in ses.ts:

- ...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY- ? { credentials: { accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY } }- : {}),+ ...getAwsCredentialOptions(),

Apply the same replacement in the second occurrence in ses.ts and in sns.ts.

Also applies to: 52-54

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/web/src/server/aws/ses.ts` around lines 33 - 35, Extract the repeated
conditional credential spread into a shared helper (e.g.
getAwsCredentialOptions) that reads env.AWS_ACCESS_KEY_ID and
env.AWS_SECRET_ACCESS_KEY and returns either { credentials: { accessKeyId,
secretAccessKey } } or {}; then replace the inline conditional spread used when
constructing the STS client, SES client (the block containing
...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY ? { credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY }
} : {}) in ses.ts) and the SNS client in sns.ts with a call to
getAwsCredentialOptions(), ensuring the helper is exported from a common module
(e.g. credentials.ts) and imported where needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/web/src/server/aws/ses.ts`:
- Around line 33-35: Extract the repeated conditional credential spread into a
shared helper (e.g. getAwsCredentialOptions) that reads env.AWS_ACCESS_KEY_ID
and env.AWS_SECRET_ACCESS_KEY and returns either { credentials: { accessKeyId,
secretAccessKey } } or {}; then replace the inline conditional spread used when
constructing the STS client, SES client (the block containing
...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY ? { credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY }
} : {}) in ses.ts) and the SNS client in sns.ts with a call to
getAwsCredentialOptions(), ensuring the helper is exported from a common module
(e.g. credentials.ts) and imported where needed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 59ef1c51-59a4-4cf8-9644-0f3ad9c00c0f

📥 Commits

Reviewing files that changed from the base of the PR and between 964bbf9 and 83258bf.

📒 Files selected for processing (7)
  • .env.example
  • .env.selfhost.example
  • apps/web/.env.test.example
  • apps/web/src/env.js
  • apps/web/src/server/aws/ses.ts
  • apps/web/src/server/aws/sns.ts
  • apps/web/src/test/setup/setup-env.ts

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/web/src/env.js`:
- Around line 34-35: The environment schema currently allows AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY to be set independently which lets code in
apps/web/src/server/aws/ses.ts and apps/web/src/server/aws/sns.ts silently fall
back to the default provider when only one credential is present; update the zod
schema for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to validate they are
either both present or both absent (e.g., using a .refine or a custom validator)
so the app fails fast with a clear error when only one credential is provided,
and ensure any code that reads these vars (SES/SNS initialization) relies on
that validated pair rather than tolerating partial config.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d7aa3fb3-6172-4517-80bd-b5a93802008a

📥 Commits

Reviewing files that changed from the base of the PR and between 83258bf and 4277fb8.

📒 Files selected for processing (1)
  • apps/web/src/env.js

Comment threadapps/web/src/env.js
…al-config guard
- Move the credential spread logic into a single credentials.ts helper
so SESv2Client, STSClient, and SNSClient all share one implementation
- Throw a clear error if only one of AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY
is set, preventing silent fallback to the default provider chain with a
half-configured environment
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/web/src/server/aws/credentials.ts`:
- Around line 4-19: The credentials helper currently only returns accessKeyId
and secretAccessKey, which breaks temporary AWS creds; add support for
AWS_SESSION_TOKEN by adding AWS_SESSION_TOKEN to your env.js schema and
runtimeEnv, then update the return object in
apps/web/src/server/aws/credentials.ts to conditionally include sessionToken
(e.g., when env.AWS_SESSION_TOKEN is present, add credentials.sessionToken =
env.AWS_SESSION_TOKEN) alongside accessKeyId and secretAccessKey, and update
test fixtures and .env.example to include an optional AWS_SESSION_TOKEN entry so
temporary credential flows are exercised.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2d02e951-f64f-4566-99ee-986b878bc362

📥 Commits

Reviewing files that changed from the base of the PR and between 4277fb8 and 5c816be.

📒 Files selected for processing (3)
  • apps/web/src/server/aws/credentials.ts
  • apps/web/src/server/aws/ses.ts
  • apps/web/src/server/aws/sns.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/src/server/aws/sns.ts
  • apps/web/src/server/aws/ses.ts

Comment on lines +4 to +19
const hasKey = !!env.AWS_ACCESS_KEY_ID;
const hasSecret = !!env.AWS_SECRET_ACCESS_KEY;

if (hasKey !== hasSecret) {
throw new Error(
"AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must both be set or both be omitted"
);
}

if (hasKey) {
return {
credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID!,
secretAccessKey: env.AWS_SECRET_ACCESS_KEY!,
},
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash# Verify whether AWS_SESSION_TOKEN is modeled and propagated in current PR surface.# Expected: references in env schema/mapping + credentials helper + (optionally) env examples.
rg -n -C3 '\bAWS_SESSION_TOKEN\b' \
apps/web/src/env.js \
apps/web/src/server/aws/credentials.ts \
apps/web/src/server/aws/ses.ts \
apps/web/src/server/aws/sns.ts \
.env.example \
.env.selfhost.example \
apps/web/.env.test.example ||true

Repository: usesend/useSend

Length of output: 41


🏁 Script executed:

# First, let's find the actual env schema/configuration file
fd -e js -e ts -e json apps/web/src/ | grep -i env | head -20

Repository: usesend/useSend

Length of output: 417


🏁 Script executed:

# Let's examine the credentials.ts file in full
cat -n apps/web/src/server/aws/credentials.ts

Repository: usesend/useSend

Length of output: 713


🏁 Script executed:

# Check the env.js or env schema structure
fd -type f -name "env*" apps/web/src/ | head -10

Repository: usesend/useSend

Length of output: 230


🏁 Script executed:

# Find env configuration files more carefully
find apps/web/src -name "env*" -type f | head -20

Repository: usesend/useSend

Length of output: 79


🏁 Script executed:

# Also search for where env is exported from
rg -l "export.*env" apps/web/src --type ts --type js | head -10

Repository: usesend/useSend

Length of output: 196


🏁 Script executed:

# Look for AWS configuration in existing code
rg "AWS_ACCESS_KEY_ID|AWS_SECRET_ACCESS_KEY" apps/web/src --type ts --type js -A 2 -B 2

Repository: usesend/useSend

Length of output: 2484


🏁 Script executed:

# Read the full env.js file
cat -n apps/web/src/env.js

Repository: usesend/useSend

Length of output: 7193


🏁 Script executed:

# Check AWS SDK documentation expectations for sessionToken# Look for any existing usage or patterns of sessionToken in the codebase
rg "sessionToken|session_token" apps/web --type ts --type js

Repository: usesend/useSend

Length of output: 41


🏁 Script executed:

# Check how AWS SDK is being used for SES and SNS
cat -n apps/web/src/server/aws/ses.ts | head -50

Repository: usesend/useSend

Length of output: 1938


🏁 Script executed:

# Look for any auth-related issues or comments in AWS files
rg "auth|sign|credential|temporary|session" apps/web/src/server/aws/ --type ts -i

Repository: usesend/useSend

Length of output: 781


🏁 Script executed:

# Check AWS SDK version/package being used
rg "@aws-sdk|aws-sdk" apps/web/package.json

Repository: usesend/useSend

Length of output: 265


Add AWS_SESSION_TOKEN support to credentials helper for temporary AWS credentials.

AWS SDK v3 requires sessionToken when using temporary credentials (from STS, IAM roles, or AssumeRole). The current implementation only handles accessKeyId and secretAccessKey, which works for long-lived IAM credentials but will fail with temporary credentials.

Add AWS_SESSION_TOKEN as an optional environment variable in env.js schema and runtimeEnv, then conditionally include it in the returned credentials object in credentials.ts. Update test setup and .env.example files as needed.

Suggested patch
 export function getAwsCredentialOptions() {
const hasKey = !!env.AWS_ACCESS_KEY_ID;
const hasSecret = !!env.AWS_SECRET_ACCESS_KEY;
+ const hasSessionToken = !!env.AWS_SESSION_TOKEN;
if (hasKey !== hasSecret) {
throw new Error(
"AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must both be set or both be omitted"
);
}
if (hasKey) {
return {
credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID!,
secretAccessKey: env.AWS_SECRET_ACCESS_KEY!,
+ ...(hasSessionToken ? { sessionToken: env.AWS_SESSION_TOKEN! } : {}),
},
};
}
return {};
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/web/src/server/aws/credentials.ts` around lines 4 - 19, The credentials
helper currently only returns accessKeyId and secretAccessKey, which breaks
temporary AWS creds; add support for AWS_SESSION_TOKEN by adding
AWS_SESSION_TOKEN to your env.js schema and runtimeEnv, then update the return
object in apps/web/src/server/aws/credentials.ts to conditionally include
sessionToken (e.g., when env.AWS_SESSION_TOKEN is present, add
credentials.sessionToken = env.AWS_SESSION_TOKEN) alongside accessKeyId and
secretAccessKey, and update test fixtures and .env.example to include an
optional AWS_SESSION_TOKEN entry so temporary credential flows are exercised.

@KMKoushik

Copy link
Copy Markdown
Member

merged with some changes in #401. ty

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feat: Avoid hardcoding AWS credentials & support standard AWS env variables

3 participants

@purva-8@KMKoushik
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' feat: support standard AWS env vars and default credential chain by purva-8 · Pull Request #395 · usesend/useSend · GitHub
Skip to content

feat: support standard AWS env vars and default credential chain - #395

Closed
purva-8 wants to merge 3 commits into
usesend:mainfrom
purva-8:feat/standard-aws-env-vars
Closed

feat: support standard AWS env vars and default credential chain#395
purva-8 wants to merge 3 commits into
usesend:mainfrom
purva-8:feat/standard-aws-env-vars

Conversation

@purva-8

@purva-8purva-8 commented May 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes#316

  • RenameAWS_ACCESS_KEYAWS_ACCESS_KEY_ID and AWS_SECRET_KEYAWS_SECRET_ACCESS_KEY to match the AWS standard naming convention used by the SDK, CLI, and IAM tooling
  • Make credentials optional: both vars are now z.string().optional() in the env schema
  • Default credential chain: when the vars are absent, the credentials object is omitted from SESv2Client, STSClient, and SNSClient — the AWS SDK automatically falls back to its default provider chain (IAM roles, ECS/EKS task roles, EC2 instance profiles, ~/.aws/credentials, etc.)
  • Backward compatibility: the runtimeEnv falls back to the old names (?? process.env.AWS_ACCESS_KEY) so existing deployments don't break without a config change

Files changed

FileChange
apps/web/src/env.jsRename schema keys, make optional, add backward-compat fallback
apps/web/src/server/aws/ses.tsConditionally pass credentials to SESv2Client / STSClient
apps/web/src/server/aws/sns.tsConditionally pass credentials to SNSClient
apps/web/src/test/setup/setup-env.tsUpdate test env keys
apps/web/.env.test.exampleUpdate example keys
.env.exampleUpdate example keys
.env.selfhost.exampleUpdate example keys, improve comment

Test plan

  • Existing deployments using the old AWS_ACCESS_KEY / AWS_SECRET_KEY names continue to work (backward-compat fallback)
  • Deployments using the new AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY names work
  • Deployments on ECS/EKS/EC2 with an IAM role and no credential env vars can boot and send email via the default provider chain
  • Unit tests pass (pnpm test)

Summary by cubic

Switches to AWS-standard env vars AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY and uses the AWS default credential chain when unset. Adds a shared credential helper that errors on partial configs; keeps backward compatibility and only passes credentials to SESv2, STS, and SNS when both vars are set.

  • New Features

    • Credentials are optional; SDK default chain is used when unset.
    • New getAwsCredentialOptions centralizes logic for SESv2Client, STSClient, and SNSClient.
    • Throws if only one of AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY is set.
  • Migration

    • Rename AWS_ACCESS_KEYAWS_ACCESS_KEY_ID and AWS_SECRET_KEYAWS_SECRET_ACCESS_KEY.
    • On IAM-role deployments, omit these vars to rely on the default chain.
    • Existing setups using old names keep working; migrate when convenient.

Written for commit 5c816be. Summary will update on new commits.

Summary by CodeRabbit

  • Chores
    • Renamed AWS credential environment variables from AWS_ACCESS_KEY/AWS_SECRET_KEY to AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY across examples and test configs.
    • Updated runtime validation to accept the new variables while falling back to the legacy names for compatibility.
    • Added credential-handling checks to ensure both new variables are set together (or omitted) to avoid misconfiguration.

Replace non-standard AWS_ACCESS_KEY / AWS_SECRET_KEY with the AWS-standard
AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY. The old names are kept as
fallbacks in the runtimeEnv for backward compatibility.
Both vars are now optional. When omitted, the credentials object is not
passed to SESv2Client, STSClient, or SNSClient — the AWS SDK then falls
back to its default provider chain (IAM roles, ECS task roles, instance
profiles, etc.), which is the recommended approach for cloud-native deployments.
Closesusesend#316
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
CopilotAI review requested due to automatic review settings May 2, 2026 12:24
@vercel

vercelBot commented May 2, 2026

Copy link
Copy Markdown

@purva-8 is attempting to deploy a commit to the kmkoushik's projects Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai

coderabbitaiBot commented May 2, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request updates AWS credential variable naming conventions across the codebase. Environment configuration files (.env.example, .env.selfhost.example, and apps/web/.env.test.example) are modified to use standard AWS naming (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY instead of AWS_ACCESS_KEY and AWS_SECRET_KEY). The environment schema in apps/web/src/env.js is updated to validate these new optional variables with fallback support for legacy names. AWS service clients in ses.ts and sns.ts are refactored to conditionally inject credentials using the new variable names. Test environment setup is similarly updated to populate the new credential variable names.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe title accurately summarizes the main changes: supporting standard AWS environment variables and enabling use of the default credential chain.
Linked Issues check✅ PassedAll coding requirements from issue #316 are met: standard AWS env vars are supported, credentials are optional, and the default credential chain can be used.
Out of Scope Changes check✅ PassedAll changes directly support the PR objectives of renaming AWS variables, making credentials optional, and maintaining backward compatibility.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 6/8 reviews remaining, refill in 9 minutes and 41 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the web app’s AWS credential handling to support standard AWS environment variable names and to allow the AWS SDK default credential provider chain when static credentials aren’t provided (fixing #316).

Changes:

  • Renames AWS_ACCESS_KEY / AWS_SECRET_KEY to AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY (with legacy fallback).
  • Makes AWS credential env vars optional and conditionally omits the credentials override for AWS SDK clients.
  • Updates test setup and example env files to reflect the new variable names.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
FileDescription
apps/web/src/env.jsUpdates env schema keys and adds legacy fallback in runtimeEnv.
apps/web/src/server/aws/ses.tsConditionally passes credentials to STSClient and SESv2Client.
apps/web/src/server/aws/sns.tsConditionally passes credentials to SNSClient.
apps/web/src/test/setup/setup-env.tsUpdates test env defaults to new AWS credential keys.
apps/web/.env.test.exampleUpdates example AWS credential keys for tests.
.env.exampleUpdates example AWS credential keys for local/dev.
.env.selfhost.exampleUpdates example keys and clarifies optional credential chain usage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadapps/web/src/env.js Outdated
Comment threadapps/web/src/env.js
Comment threadapps/web/src/server/aws/ses.ts Outdated
Comment threadapps/web/src/server/aws/sns.ts Outdated

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/web/src/server/aws/ses.ts (1)

33-35: ⚡ Quick win

Extract the repeated credential-options construction to a shared helper.

The same conditional spread appears three times: STS client (Line 33–35), SES client (Line 52–54), and the SNS client in sns.ts (Line 13–15). If the logic ever needs to add sessionToken or change the guard condition, all three sites must be updated in sync.

♻️ Proposed refactor

Add a shared helper (e.g. in apps/web/src/server/aws/credentials.ts):

import{env}from"~/env";exportfunctiongetAwsCredentialOptions(){if(env.AWS_ACCESS_KEY_ID&&env.AWS_SECRET_ACCESS_KEY){return{credentials: {accessKeyId: env.AWS_ACCESS_KEY_ID,secretAccessKey: env.AWS_SECRET_ACCESS_KEY,},};}return{};}

Then in ses.ts:

- ...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY- ? { credentials: { accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY } }- : {}),+ ...getAwsCredentialOptions(),

Apply the same replacement in the second occurrence in ses.ts and in sns.ts.

Also applies to: 52-54

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/web/src/server/aws/ses.ts` around lines 33 - 35, Extract the repeated
conditional credential spread into a shared helper (e.g.
getAwsCredentialOptions) that reads env.AWS_ACCESS_KEY_ID and
env.AWS_SECRET_ACCESS_KEY and returns either { credentials: { accessKeyId,
secretAccessKey } } or {}; then replace the inline conditional spread used when
constructing the STS client, SES client (the block containing
...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY ? { credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY }
} : {}) in ses.ts) and the SNS client in sns.ts with a call to
getAwsCredentialOptions(), ensuring the helper is exported from a common module
(e.g. credentials.ts) and imported where needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/web/src/server/aws/ses.ts`:
- Around line 33-35: Extract the repeated conditional credential spread into a
shared helper (e.g. getAwsCredentialOptions) that reads env.AWS_ACCESS_KEY_ID
and env.AWS_SECRET_ACCESS_KEY and returns either { credentials: { accessKeyId,
secretAccessKey } } or {}; then replace the inline conditional spread used when
constructing the STS client, SES client (the block containing
...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY ? { credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY }
} : {}) in ses.ts) and the SNS client in sns.ts with a call to
getAwsCredentialOptions(), ensuring the helper is exported from a common module
(e.g. credentials.ts) and imported where needed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 59ef1c51-59a4-4cf8-9644-0f3ad9c00c0f

📥 Commits

Reviewing files that changed from the base of the PR and between 964bbf9 and 83258bf.

📒 Files selected for processing (7)
  • .env.example
  • .env.selfhost.example
  • apps/web/.env.test.example
  • apps/web/src/env.js
  • apps/web/src/server/aws/ses.ts
  • apps/web/src/server/aws/sns.ts
  • apps/web/src/test/setup/setup-env.ts

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/web/src/env.js`:
- Around line 34-35: The environment schema currently allows AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY to be set independently which lets code in
apps/web/src/server/aws/ses.ts and apps/web/src/server/aws/sns.ts silently fall
back to the default provider when only one credential is present; update the zod
schema for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to validate they are
either both present or both absent (e.g., using a .refine or a custom validator)
so the app fails fast with a clear error when only one credential is provided,
and ensure any code that reads these vars (SES/SNS initialization) relies on
that validated pair rather than tolerating partial config.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d7aa3fb3-6172-4517-80bd-b5a93802008a

📥 Commits

Reviewing files that changed from the base of the PR and between 83258bf and 4277fb8.

📒 Files selected for processing (1)
  • apps/web/src/env.js

Comment threadapps/web/src/env.js
…al-config guard
- Move the credential spread logic into a single credentials.ts helper
so SESv2Client, STSClient, and SNSClient all share one implementation
- Throw a clear error if only one of AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY
is set, preventing silent fallback to the default provider chain with a
half-configured environment
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/web/src/server/aws/credentials.ts`:
- Around line 4-19: The credentials helper currently only returns accessKeyId
and secretAccessKey, which breaks temporary AWS creds; add support for
AWS_SESSION_TOKEN by adding AWS_SESSION_TOKEN to your env.js schema and
runtimeEnv, then update the return object in
apps/web/src/server/aws/credentials.ts to conditionally include sessionToken
(e.g., when env.AWS_SESSION_TOKEN is present, add credentials.sessionToken =
env.AWS_SESSION_TOKEN) alongside accessKeyId and secretAccessKey, and update
test fixtures and .env.example to include an optional AWS_SESSION_TOKEN entry so
temporary credential flows are exercised.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2d02e951-f64f-4566-99ee-986b878bc362

📥 Commits

Reviewing files that changed from the base of the PR and between 4277fb8 and 5c816be.

📒 Files selected for processing (3)
  • apps/web/src/server/aws/credentials.ts
  • apps/web/src/server/aws/ses.ts
  • apps/web/src/server/aws/sns.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/src/server/aws/sns.ts
  • apps/web/src/server/aws/ses.ts

Comment on lines +4 to +19
const hasKey = !!env.AWS_ACCESS_KEY_ID;
const hasSecret = !!env.AWS_SECRET_ACCESS_KEY;

if (hasKey !== hasSecret) {
throw new Error(
"AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must both be set or both be omitted"
);
}

if (hasKey) {
return {
credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID!,
secretAccessKey: env.AWS_SECRET_ACCESS_KEY!,
},
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash# Verify whether AWS_SESSION_TOKEN is modeled and propagated in current PR surface.# Expected: references in env schema/mapping + credentials helper + (optionally) env examples.
rg -n -C3 '\bAWS_SESSION_TOKEN\b' \
apps/web/src/env.js \
apps/web/src/server/aws/credentials.ts \
apps/web/src/server/aws/ses.ts \
apps/web/src/server/aws/sns.ts \
.env.example \
.env.selfhost.example \
apps/web/.env.test.example ||true

Repository: usesend/useSend

Length of output: 41


🏁 Script executed:

# First, let's find the actual env schema/configuration file
fd -e js -e ts -e json apps/web/src/ | grep -i env | head -20

Repository: usesend/useSend

Length of output: 417


🏁 Script executed:

# Let's examine the credentials.ts file in full
cat -n apps/web/src/server/aws/credentials.ts

Repository: usesend/useSend

Length of output: 713


🏁 Script executed:

# Check the env.js or env schema structure
fd -type f -name "env*" apps/web/src/ | head -10

Repository: usesend/useSend

Length of output: 230


🏁 Script executed:

# Find env configuration files more carefully
find apps/web/src -name "env*" -type f | head -20

Repository: usesend/useSend

Length of output: 79


🏁 Script executed:

# Also search for where env is exported from
rg -l "export.*env" apps/web/src --type ts --type js | head -10

Repository: usesend/useSend

Length of output: 196


🏁 Script executed:

# Look for AWS configuration in existing code
rg "AWS_ACCESS_KEY_ID|AWS_SECRET_ACCESS_KEY" apps/web/src --type ts --type js -A 2 -B 2

Repository: usesend/useSend

Length of output: 2484


🏁 Script executed:

# Read the full env.js file
cat -n apps/web/src/env.js

Repository: usesend/useSend

Length of output: 7193


🏁 Script executed:

# Check AWS SDK documentation expectations for sessionToken# Look for any existing usage or patterns of sessionToken in the codebase
rg "sessionToken|session_token" apps/web --type ts --type js

Repository: usesend/useSend

Length of output: 41


🏁 Script executed:

# Check how AWS SDK is being used for SES and SNS
cat -n apps/web/src/server/aws/ses.ts | head -50

Repository: usesend/useSend

Length of output: 1938


🏁 Script executed:

# Look for any auth-related issues or comments in AWS files
rg "auth|sign|credential|temporary|session" apps/web/src/server/aws/ --type ts -i

Repository: usesend/useSend

Length of output: 781


🏁 Script executed:

# Check AWS SDK version/package being used
rg "@aws-sdk|aws-sdk" apps/web/package.json

Repository: usesend/useSend

Length of output: 265


Add AWS_SESSION_TOKEN support to credentials helper for temporary AWS credentials.

AWS SDK v3 requires sessionToken when using temporary credentials (from STS, IAM roles, or AssumeRole). The current implementation only handles accessKeyId and secretAccessKey, which works for long-lived IAM credentials but will fail with temporary credentials.

Add AWS_SESSION_TOKEN as an optional environment variable in env.js schema and runtimeEnv, then conditionally include it in the returned credentials object in credentials.ts. Update test setup and .env.example files as needed.

Suggested patch
 export function getAwsCredentialOptions() {
const hasKey = !!env.AWS_ACCESS_KEY_ID;
const hasSecret = !!env.AWS_SECRET_ACCESS_KEY;
+ const hasSessionToken = !!env.AWS_SESSION_TOKEN;
if (hasKey !== hasSecret) {
throw new Error(
"AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must both be set or both be omitted"
);
}
if (hasKey) {
return {
credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID!,
secretAccessKey: env.AWS_SECRET_ACCESS_KEY!,
+ ...(hasSessionToken ? { sessionToken: env.AWS_SESSION_TOKEN! } : {}),
},
};
}
return {};
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/web/src/server/aws/credentials.ts` around lines 4 - 19, The credentials
helper currently only returns accessKeyId and secretAccessKey, which breaks
temporary AWS creds; add support for AWS_SESSION_TOKEN by adding
AWS_SESSION_TOKEN to your env.js schema and runtimeEnv, then update the return
object in apps/web/src/server/aws/credentials.ts to conditionally include
sessionToken (e.g., when env.AWS_SESSION_TOKEN is present, add
credentials.sessionToken = env.AWS_SESSION_TOKEN) alongside accessKeyId and
secretAccessKey, and update test fixtures and .env.example to include an
optional AWS_SESSION_TOKEN entry so temporary credential flows are exercised.

@KMKoushik

Copy link
Copy Markdown
Member

merged with some changes in #401. ty

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feat: Avoid hardcoding AWS credentials & support standard AWS env variables

3 participants

@purva-8@KMKoushik
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' feat: support standard AWS env vars and default credential chain by purva-8 · Pull Request #395 · usesend/useSend · GitHub
Skip to content

feat: support standard AWS env vars and default credential chain - #395

Closed
purva-8 wants to merge 3 commits into
usesend:mainfrom
purva-8:feat/standard-aws-env-vars
Closed

feat: support standard AWS env vars and default credential chain#395
purva-8 wants to merge 3 commits into
usesend:mainfrom
purva-8:feat/standard-aws-env-vars

Conversation

@purva-8

@purva-8purva-8 commented May 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes#316

  • RenameAWS_ACCESS_KEYAWS_ACCESS_KEY_ID and AWS_SECRET_KEYAWS_SECRET_ACCESS_KEY to match the AWS standard naming convention used by the SDK, CLI, and IAM tooling
  • Make credentials optional: both vars are now z.string().optional() in the env schema
  • Default credential chain: when the vars are absent, the credentials object is omitted from SESv2Client, STSClient, and SNSClient — the AWS SDK automatically falls back to its default provider chain (IAM roles, ECS/EKS task roles, EC2 instance profiles, ~/.aws/credentials, etc.)
  • Backward compatibility: the runtimeEnv falls back to the old names (?? process.env.AWS_ACCESS_KEY) so existing deployments don't break without a config change

Files changed

FileChange
apps/web/src/env.jsRename schema keys, make optional, add backward-compat fallback
apps/web/src/server/aws/ses.tsConditionally pass credentials to SESv2Client / STSClient
apps/web/src/server/aws/sns.tsConditionally pass credentials to SNSClient
apps/web/src/test/setup/setup-env.tsUpdate test env keys
apps/web/.env.test.exampleUpdate example keys
.env.exampleUpdate example keys
.env.selfhost.exampleUpdate example keys, improve comment

Test plan

  • Existing deployments using the old AWS_ACCESS_KEY / AWS_SECRET_KEY names continue to work (backward-compat fallback)
  • Deployments using the new AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY names work
  • Deployments on ECS/EKS/EC2 with an IAM role and no credential env vars can boot and send email via the default provider chain
  • Unit tests pass (pnpm test)

Summary by cubic

Switches to AWS-standard env vars AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY and uses the AWS default credential chain when unset. Adds a shared credential helper that errors on partial configs; keeps backward compatibility and only passes credentials to SESv2, STS, and SNS when both vars are set.

  • New Features

    • Credentials are optional; SDK default chain is used when unset.
    • New getAwsCredentialOptions centralizes logic for SESv2Client, STSClient, and SNSClient.
    • Throws if only one of AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY is set.
  • Migration

    • Rename AWS_ACCESS_KEYAWS_ACCESS_KEY_ID and AWS_SECRET_KEYAWS_SECRET_ACCESS_KEY.
    • On IAM-role deployments, omit these vars to rely on the default chain.
    • Existing setups using old names keep working; migrate when convenient.

Written for commit 5c816be. Summary will update on new commits.

Summary by CodeRabbit

  • Chores
    • Renamed AWS credential environment variables from AWS_ACCESS_KEY/AWS_SECRET_KEY to AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY across examples and test configs.
    • Updated runtime validation to accept the new variables while falling back to the legacy names for compatibility.
    • Added credential-handling checks to ensure both new variables are set together (or omitted) to avoid misconfiguration.

Replace non-standard AWS_ACCESS_KEY / AWS_SECRET_KEY with the AWS-standard
AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY. The old names are kept as
fallbacks in the runtimeEnv for backward compatibility.
Both vars are now optional. When omitted, the credentials object is not
passed to SESv2Client, STSClient, or SNSClient — the AWS SDK then falls
back to its default provider chain (IAM roles, ECS task roles, instance
profiles, etc.), which is the recommended approach for cloud-native deployments.
Closesusesend#316
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
CopilotAI review requested due to automatic review settings May 2, 2026 12:24
@vercel

vercelBot commented May 2, 2026

Copy link
Copy Markdown

@purva-8 is attempting to deploy a commit to the kmkoushik's projects Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai

coderabbitaiBot commented May 2, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request updates AWS credential variable naming conventions across the codebase. Environment configuration files (.env.example, .env.selfhost.example, and apps/web/.env.test.example) are modified to use standard AWS naming (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY instead of AWS_ACCESS_KEY and AWS_SECRET_KEY). The environment schema in apps/web/src/env.js is updated to validate these new optional variables with fallback support for legacy names. AWS service clients in ses.ts and sns.ts are refactored to conditionally inject credentials using the new variable names. Test environment setup is similarly updated to populate the new credential variable names.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe title accurately summarizes the main changes: supporting standard AWS environment variables and enabling use of the default credential chain.
Linked Issues check✅ PassedAll coding requirements from issue #316 are met: standard AWS env vars are supported, credentials are optional, and the default credential chain can be used.
Out of Scope Changes check✅ PassedAll changes directly support the PR objectives of renaming AWS variables, making credentials optional, and maintaining backward compatibility.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 6/8 reviews remaining, refill in 9 minutes and 41 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the web app’s AWS credential handling to support standard AWS environment variable names and to allow the AWS SDK default credential provider chain when static credentials aren’t provided (fixing #316).

Changes:

  • Renames AWS_ACCESS_KEY / AWS_SECRET_KEY to AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY (with legacy fallback).
  • Makes AWS credential env vars optional and conditionally omits the credentials override for AWS SDK clients.
  • Updates test setup and example env files to reflect the new variable names.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
FileDescription
apps/web/src/env.jsUpdates env schema keys and adds legacy fallback in runtimeEnv.
apps/web/src/server/aws/ses.tsConditionally passes credentials to STSClient and SESv2Client.
apps/web/src/server/aws/sns.tsConditionally passes credentials to SNSClient.
apps/web/src/test/setup/setup-env.tsUpdates test env defaults to new AWS credential keys.
apps/web/.env.test.exampleUpdates example AWS credential keys for tests.
.env.exampleUpdates example AWS credential keys for local/dev.
.env.selfhost.exampleUpdates example keys and clarifies optional credential chain usage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadapps/web/src/env.js Outdated
Comment threadapps/web/src/env.js
Comment threadapps/web/src/server/aws/ses.ts Outdated
Comment threadapps/web/src/server/aws/sns.ts Outdated

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/web/src/server/aws/ses.ts (1)

33-35: ⚡ Quick win

Extract the repeated credential-options construction to a shared helper.

The same conditional spread appears three times: STS client (Line 33–35), SES client (Line 52–54), and the SNS client in sns.ts (Line 13–15). If the logic ever needs to add sessionToken or change the guard condition, all three sites must be updated in sync.

♻️ Proposed refactor

Add a shared helper (e.g. in apps/web/src/server/aws/credentials.ts):

import{env}from"~/env";exportfunctiongetAwsCredentialOptions(){if(env.AWS_ACCESS_KEY_ID&&env.AWS_SECRET_ACCESS_KEY){return{credentials: {accessKeyId: env.AWS_ACCESS_KEY_ID,secretAccessKey: env.AWS_SECRET_ACCESS_KEY,},};}return{};}

Then in ses.ts:

- ...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY- ? { credentials: { accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY } }- : {}),+ ...getAwsCredentialOptions(),

Apply the same replacement in the second occurrence in ses.ts and in sns.ts.

Also applies to: 52-54

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/web/src/server/aws/ses.ts` around lines 33 - 35, Extract the repeated
conditional credential spread into a shared helper (e.g.
getAwsCredentialOptions) that reads env.AWS_ACCESS_KEY_ID and
env.AWS_SECRET_ACCESS_KEY and returns either { credentials: { accessKeyId,
secretAccessKey } } or {}; then replace the inline conditional spread used when
constructing the STS client, SES client (the block containing
...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY ? { credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY }
} : {}) in ses.ts) and the SNS client in sns.ts with a call to
getAwsCredentialOptions(), ensuring the helper is exported from a common module
(e.g. credentials.ts) and imported where needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/web/src/server/aws/ses.ts`:
- Around line 33-35: Extract the repeated conditional credential spread into a
shared helper (e.g. getAwsCredentialOptions) that reads env.AWS_ACCESS_KEY_ID
and env.AWS_SECRET_ACCESS_KEY and returns either { credentials: { accessKeyId,
secretAccessKey } } or {}; then replace the inline conditional spread used when
constructing the STS client, SES client (the block containing
...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY ? { credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY }
} : {}) in ses.ts) and the SNS client in sns.ts with a call to
getAwsCredentialOptions(), ensuring the helper is exported from a common module
(e.g. credentials.ts) and imported where needed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 59ef1c51-59a4-4cf8-9644-0f3ad9c00c0f

📥 Commits

Reviewing files that changed from the base of the PR and between 964bbf9 and 83258bf.

📒 Files selected for processing (7)
  • .env.example
  • .env.selfhost.example
  • apps/web/.env.test.example
  • apps/web/src/env.js
  • apps/web/src/server/aws/ses.ts
  • apps/web/src/server/aws/sns.ts
  • apps/web/src/test/setup/setup-env.ts

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/web/src/env.js`:
- Around line 34-35: The environment schema currently allows AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY to be set independently which lets code in
apps/web/src/server/aws/ses.ts and apps/web/src/server/aws/sns.ts silently fall
back to the default provider when only one credential is present; update the zod
schema for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to validate they are
either both present or both absent (e.g., using a .refine or a custom validator)
so the app fails fast with a clear error when only one credential is provided,
and ensure any code that reads these vars (SES/SNS initialization) relies on
that validated pair rather than tolerating partial config.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d7aa3fb3-6172-4517-80bd-b5a93802008a

📥 Commits

Reviewing files that changed from the base of the PR and between 83258bf and 4277fb8.

📒 Files selected for processing (1)
  • apps/web/src/env.js

Comment threadapps/web/src/env.js
…al-config guard
- Move the credential spread logic into a single credentials.ts helper
so SESv2Client, STSClient, and SNSClient all share one implementation
- Throw a clear error if only one of AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY
is set, preventing silent fallback to the default provider chain with a
half-configured environment
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/web/src/server/aws/credentials.ts`:
- Around line 4-19: The credentials helper currently only returns accessKeyId
and secretAccessKey, which breaks temporary AWS creds; add support for
AWS_SESSION_TOKEN by adding AWS_SESSION_TOKEN to your env.js schema and
runtimeEnv, then update the return object in
apps/web/src/server/aws/credentials.ts to conditionally include sessionToken
(e.g., when env.AWS_SESSION_TOKEN is present, add credentials.sessionToken =
env.AWS_SESSION_TOKEN) alongside accessKeyId and secretAccessKey, and update
test fixtures and .env.example to include an optional AWS_SESSION_TOKEN entry so
temporary credential flows are exercised.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2d02e951-f64f-4566-99ee-986b878bc362

📥 Commits

Reviewing files that changed from the base of the PR and between 4277fb8 and 5c816be.

📒 Files selected for processing (3)
  • apps/web/src/server/aws/credentials.ts
  • apps/web/src/server/aws/ses.ts
  • apps/web/src/server/aws/sns.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/src/server/aws/sns.ts
  • apps/web/src/server/aws/ses.ts

Comment on lines +4 to +19
const hasKey = !!env.AWS_ACCESS_KEY_ID;
const hasSecret = !!env.AWS_SECRET_ACCESS_KEY;

if (hasKey !== hasSecret) {
throw new Error(
"AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must both be set or both be omitted"
);
}

if (hasKey) {
return {
credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID!,
secretAccessKey: env.AWS_SECRET_ACCESS_KEY!,
},
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash# Verify whether AWS_SESSION_TOKEN is modeled and propagated in current PR surface.# Expected: references in env schema/mapping + credentials helper + (optionally) env examples.
rg -n -C3 '\bAWS_SESSION_TOKEN\b' \
apps/web/src/env.js \
apps/web/src/server/aws/credentials.ts \
apps/web/src/server/aws/ses.ts \
apps/web/src/server/aws/sns.ts \
.env.example \
.env.selfhost.example \
apps/web/.env.test.example ||true

Repository: usesend/useSend

Length of output: 41


🏁 Script executed:

# First, let's find the actual env schema/configuration file
fd -e js -e ts -e json apps/web/src/ | grep -i env | head -20

Repository: usesend/useSend

Length of output: 417


🏁 Script executed:

# Let's examine the credentials.ts file in full
cat -n apps/web/src/server/aws/credentials.ts

Repository: usesend/useSend

Length of output: 713


🏁 Script executed:

# Check the env.js or env schema structure
fd -type f -name "env*" apps/web/src/ | head -10

Repository: usesend/useSend

Length of output: 230


🏁 Script executed:

# Find env configuration files more carefully
find apps/web/src -name "env*" -type f | head -20

Repository: usesend/useSend

Length of output: 79


🏁 Script executed:

# Also search for where env is exported from
rg -l "export.*env" apps/web/src --type ts --type js | head -10

Repository: usesend/useSend

Length of output: 196


🏁 Script executed:

# Look for AWS configuration in existing code
rg "AWS_ACCESS_KEY_ID|AWS_SECRET_ACCESS_KEY" apps/web/src --type ts --type js -A 2 -B 2

Repository: usesend/useSend

Length of output: 2484


🏁 Script executed:

# Read the full env.js file
cat -n apps/web/src/env.js

Repository: usesend/useSend

Length of output: 7193


🏁 Script executed:

# Check AWS SDK documentation expectations for sessionToken# Look for any existing usage or patterns of sessionToken in the codebase
rg "sessionToken|session_token" apps/web --type ts --type js

Repository: usesend/useSend

Length of output: 41


🏁 Script executed:

# Check how AWS SDK is being used for SES and SNS
cat -n apps/web/src/server/aws/ses.ts | head -50

Repository: usesend/useSend

Length of output: 1938


🏁 Script executed:

# Look for any auth-related issues or comments in AWS files
rg "auth|sign|credential|temporary|session" apps/web/src/server/aws/ --type ts -i

Repository: usesend/useSend

Length of output: 781


🏁 Script executed:

# Check AWS SDK version/package being used
rg "@aws-sdk|aws-sdk" apps/web/package.json

Repository: usesend/useSend

Length of output: 265


Add AWS_SESSION_TOKEN support to credentials helper for temporary AWS credentials.

AWS SDK v3 requires sessionToken when using temporary credentials (from STS, IAM roles, or AssumeRole). The current implementation only handles accessKeyId and secretAccessKey, which works for long-lived IAM credentials but will fail with temporary credentials.

Add AWS_SESSION_TOKEN as an optional environment variable in env.js schema and runtimeEnv, then conditionally include it in the returned credentials object in credentials.ts. Update test setup and .env.example files as needed.

Suggested patch
 export function getAwsCredentialOptions() {
const hasKey = !!env.AWS_ACCESS_KEY_ID;
const hasSecret = !!env.AWS_SECRET_ACCESS_KEY;
+ const hasSessionToken = !!env.AWS_SESSION_TOKEN;
if (hasKey !== hasSecret) {
throw new Error(
"AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must both be set or both be omitted"
);
}
if (hasKey) {
return {
credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID!,
secretAccessKey: env.AWS_SECRET_ACCESS_KEY!,
+ ...(hasSessionToken ? { sessionToken: env.AWS_SESSION_TOKEN! } : {}),
},
};
}
return {};
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/web/src/server/aws/credentials.ts` around lines 4 - 19, The credentials
helper currently only returns accessKeyId and secretAccessKey, which breaks
temporary AWS creds; add support for AWS_SESSION_TOKEN by adding
AWS_SESSION_TOKEN to your env.js schema and runtimeEnv, then update the return
object in apps/web/src/server/aws/credentials.ts to conditionally include
sessionToken (e.g., when env.AWS_SESSION_TOKEN is present, add
credentials.sessionToken = env.AWS_SESSION_TOKEN) alongside accessKeyId and
secretAccessKey, and update test fixtures and .env.example to include an
optional AWS_SESSION_TOKEN entry so temporary credential flows are exercised.

@KMKoushik

Copy link
Copy Markdown
Member

merged with some changes in #401. ty

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feat: Avoid hardcoding AWS credentials & support standard AWS env variables

3 participants

@purva-8@KMKoushik
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); feat: support standard AWS env vars and default credential chain by purva-8 · Pull Request #395 · usesend/useSend · GitHub
Skip to content

feat: support standard AWS env vars and default credential chain - #395

Closed
purva-8 wants to merge 3 commits into
usesend:mainfrom
purva-8:feat/standard-aws-env-vars
Closed

feat: support standard AWS env vars and default credential chain#395
purva-8 wants to merge 3 commits into
usesend:mainfrom
purva-8:feat/standard-aws-env-vars

Conversation

@purva-8

@purva-8purva-8 commented May 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes#316

  • RenameAWS_ACCESS_KEYAWS_ACCESS_KEY_ID and AWS_SECRET_KEYAWS_SECRET_ACCESS_KEY to match the AWS standard naming convention used by the SDK, CLI, and IAM tooling
  • Make credentials optional: both vars are now z.string().optional() in the env schema
  • Default credential chain: when the vars are absent, the credentials object is omitted from SESv2Client, STSClient, and SNSClient — the AWS SDK automatically falls back to its default provider chain (IAM roles, ECS/EKS task roles, EC2 instance profiles, ~/.aws/credentials, etc.)
  • Backward compatibility: the runtimeEnv falls back to the old names (?? process.env.AWS_ACCESS_KEY) so existing deployments don't break without a config change

Files changed

FileChange
apps/web/src/env.jsRename schema keys, make optional, add backward-compat fallback
apps/web/src/server/aws/ses.tsConditionally pass credentials to SESv2Client / STSClient
apps/web/src/server/aws/sns.tsConditionally pass credentials to SNSClient
apps/web/src/test/setup/setup-env.tsUpdate test env keys
apps/web/.env.test.exampleUpdate example keys
.env.exampleUpdate example keys
.env.selfhost.exampleUpdate example keys, improve comment

Test plan

  • Existing deployments using the old AWS_ACCESS_KEY / AWS_SECRET_KEY names continue to work (backward-compat fallback)
  • Deployments using the new AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY names work
  • Deployments on ECS/EKS/EC2 with an IAM role and no credential env vars can boot and send email via the default provider chain
  • Unit tests pass (pnpm test)

Summary by cubic

Switches to AWS-standard env vars AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY and uses the AWS default credential chain when unset. Adds a shared credential helper that errors on partial configs; keeps backward compatibility and only passes credentials to SESv2, STS, and SNS when both vars are set.

  • New Features

    • Credentials are optional; SDK default chain is used when unset.
    • New getAwsCredentialOptions centralizes logic for SESv2Client, STSClient, and SNSClient.
    • Throws if only one of AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY is set.
  • Migration

    • Rename AWS_ACCESS_KEYAWS_ACCESS_KEY_ID and AWS_SECRET_KEYAWS_SECRET_ACCESS_KEY.
    • On IAM-role deployments, omit these vars to rely on the default chain.
    • Existing setups using old names keep working; migrate when convenient.

Written for commit 5c816be. Summary will update on new commits.

Summary by CodeRabbit

  • Chores
    • Renamed AWS credential environment variables from AWS_ACCESS_KEY/AWS_SECRET_KEY to AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY across examples and test configs.
    • Updated runtime validation to accept the new variables while falling back to the legacy names for compatibility.
    • Added credential-handling checks to ensure both new variables are set together (or omitted) to avoid misconfiguration.

Replace non-standard AWS_ACCESS_KEY / AWS_SECRET_KEY with the AWS-standard
AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY. The old names are kept as
fallbacks in the runtimeEnv for backward compatibility.
Both vars are now optional. When omitted, the credentials object is not
passed to SESv2Client, STSClient, or SNSClient — the AWS SDK then falls
back to its default provider chain (IAM roles, ECS task roles, instance
profiles, etc.), which is the recommended approach for cloud-native deployments.
Closesusesend#316
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
CopilotAI review requested due to automatic review settings May 2, 2026 12:24
@vercel

vercelBot commented May 2, 2026

Copy link
Copy Markdown

@purva-8 is attempting to deploy a commit to the kmkoushik's projects Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai

coderabbitaiBot commented May 2, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request updates AWS credential variable naming conventions across the codebase. Environment configuration files (.env.example, .env.selfhost.example, and apps/web/.env.test.example) are modified to use standard AWS naming (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY instead of AWS_ACCESS_KEY and AWS_SECRET_KEY). The environment schema in apps/web/src/env.js is updated to validate these new optional variables with fallback support for legacy names. AWS service clients in ses.ts and sns.ts are refactored to conditionally inject credentials using the new variable names. Test environment setup is similarly updated to populate the new credential variable names.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe title accurately summarizes the main changes: supporting standard AWS environment variables and enabling use of the default credential chain.
Linked Issues check✅ PassedAll coding requirements from issue #316 are met: standard AWS env vars are supported, credentials are optional, and the default credential chain can be used.
Out of Scope Changes check✅ PassedAll changes directly support the PR objectives of renaming AWS variables, making credentials optional, and maintaining backward compatibility.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 6/8 reviews remaining, refill in 9 minutes and 41 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the web app’s AWS credential handling to support standard AWS environment variable names and to allow the AWS SDK default credential provider chain when static credentials aren’t provided (fixing #316).

Changes:

  • Renames AWS_ACCESS_KEY / AWS_SECRET_KEY to AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY (with legacy fallback).
  • Makes AWS credential env vars optional and conditionally omits the credentials override for AWS SDK clients.
  • Updates test setup and example env files to reflect the new variable names.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
FileDescription
apps/web/src/env.jsUpdates env schema keys and adds legacy fallback in runtimeEnv.
apps/web/src/server/aws/ses.tsConditionally passes credentials to STSClient and SESv2Client.
apps/web/src/server/aws/sns.tsConditionally passes credentials to SNSClient.
apps/web/src/test/setup/setup-env.tsUpdates test env defaults to new AWS credential keys.
apps/web/.env.test.exampleUpdates example AWS credential keys for tests.
.env.exampleUpdates example AWS credential keys for local/dev.
.env.selfhost.exampleUpdates example keys and clarifies optional credential chain usage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadapps/web/src/env.js Outdated
Comment threadapps/web/src/env.js
Comment threadapps/web/src/server/aws/ses.ts Outdated
Comment threadapps/web/src/server/aws/sns.ts Outdated

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/web/src/server/aws/ses.ts (1)

33-35: ⚡ Quick win

Extract the repeated credential-options construction to a shared helper.

The same conditional spread appears three times: STS client (Line 33–35), SES client (Line 52–54), and the SNS client in sns.ts (Line 13–15). If the logic ever needs to add sessionToken or change the guard condition, all three sites must be updated in sync.

♻️ Proposed refactor

Add a shared helper (e.g. in apps/web/src/server/aws/credentials.ts):

import{env}from"~/env";exportfunctiongetAwsCredentialOptions(){if(env.AWS_ACCESS_KEY_ID&&env.AWS_SECRET_ACCESS_KEY){return{credentials: {accessKeyId: env.AWS_ACCESS_KEY_ID,secretAccessKey: env.AWS_SECRET_ACCESS_KEY,},};}return{};}

Then in ses.ts:

- ...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY- ? { credentials: { accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY } }- : {}),+ ...getAwsCredentialOptions(),

Apply the same replacement in the second occurrence in ses.ts and in sns.ts.

Also applies to: 52-54

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/web/src/server/aws/ses.ts` around lines 33 - 35, Extract the repeated
conditional credential spread into a shared helper (e.g.
getAwsCredentialOptions) that reads env.AWS_ACCESS_KEY_ID and
env.AWS_SECRET_ACCESS_KEY and returns either { credentials: { accessKeyId,
secretAccessKey } } or {}; then replace the inline conditional spread used when
constructing the STS client, SES client (the block containing
...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY ? { credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY }
} : {}) in ses.ts) and the SNS client in sns.ts with a call to
getAwsCredentialOptions(), ensuring the helper is exported from a common module
(e.g. credentials.ts) and imported where needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/web/src/server/aws/ses.ts`:
- Around line 33-35: Extract the repeated conditional credential spread into a
shared helper (e.g. getAwsCredentialOptions) that reads env.AWS_ACCESS_KEY_ID
and env.AWS_SECRET_ACCESS_KEY and returns either { credentials: { accessKeyId,
secretAccessKey } } or {}; then replace the inline conditional spread used when
constructing the STS client, SES client (the block containing
...(env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY ? { credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY }
} : {}) in ses.ts) and the SNS client in sns.ts with a call to
getAwsCredentialOptions(), ensuring the helper is exported from a common module
(e.g. credentials.ts) and imported where needed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 59ef1c51-59a4-4cf8-9644-0f3ad9c00c0f

📥 Commits

Reviewing files that changed from the base of the PR and between 964bbf9 and 83258bf.

📒 Files selected for processing (7)
  • .env.example
  • .env.selfhost.example
  • apps/web/.env.test.example
  • apps/web/src/env.js
  • apps/web/src/server/aws/ses.ts
  • apps/web/src/server/aws/sns.ts
  • apps/web/src/test/setup/setup-env.ts

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/web/src/env.js`:
- Around line 34-35: The environment schema currently allows AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY to be set independently which lets code in
apps/web/src/server/aws/ses.ts and apps/web/src/server/aws/sns.ts silently fall
back to the default provider when only one credential is present; update the zod
schema for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to validate they are
either both present or both absent (e.g., using a .refine or a custom validator)
so the app fails fast with a clear error when only one credential is provided,
and ensure any code that reads these vars (SES/SNS initialization) relies on
that validated pair rather than tolerating partial config.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d7aa3fb3-6172-4517-80bd-b5a93802008a

📥 Commits

Reviewing files that changed from the base of the PR and between 83258bf and 4277fb8.

📒 Files selected for processing (1)
  • apps/web/src/env.js

Comment threadapps/web/src/env.js
…al-config guard
- Move the credential spread logic into a single credentials.ts helper
so SESv2Client, STSClient, and SNSClient all share one implementation
- Throw a clear error if only one of AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY
is set, preventing silent fallback to the default provider chain with a
half-configured environment
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/web/src/server/aws/credentials.ts`:
- Around line 4-19: The credentials helper currently only returns accessKeyId
and secretAccessKey, which breaks temporary AWS creds; add support for
AWS_SESSION_TOKEN by adding AWS_SESSION_TOKEN to your env.js schema and
runtimeEnv, then update the return object in
apps/web/src/server/aws/credentials.ts to conditionally include sessionToken
(e.g., when env.AWS_SESSION_TOKEN is present, add credentials.sessionToken =
env.AWS_SESSION_TOKEN) alongside accessKeyId and secretAccessKey, and update
test fixtures and .env.example to include an optional AWS_SESSION_TOKEN entry so
temporary credential flows are exercised.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2d02e951-f64f-4566-99ee-986b878bc362

📥 Commits

Reviewing files that changed from the base of the PR and between 4277fb8 and 5c816be.

📒 Files selected for processing (3)
  • apps/web/src/server/aws/credentials.ts
  • apps/web/src/server/aws/ses.ts
  • apps/web/src/server/aws/sns.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/src/server/aws/sns.ts
  • apps/web/src/server/aws/ses.ts

Comment on lines +4 to +19
const hasKey = !!env.AWS_ACCESS_KEY_ID;
const hasSecret = !!env.AWS_SECRET_ACCESS_KEY;

if (hasKey !== hasSecret) {
throw new Error(
"AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must both be set or both be omitted"
);
}

if (hasKey) {
return {
credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID!,
secretAccessKey: env.AWS_SECRET_ACCESS_KEY!,
},
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash# Verify whether AWS_SESSION_TOKEN is modeled and propagated in current PR surface.# Expected: references in env schema/mapping + credentials helper + (optionally) env examples.
rg -n -C3 '\bAWS_SESSION_TOKEN\b' \
apps/web/src/env.js \
apps/web/src/server/aws/credentials.ts \
apps/web/src/server/aws/ses.ts \
apps/web/src/server/aws/sns.ts \
.env.example \
.env.selfhost.example \
apps/web/.env.test.example ||true

Repository: usesend/useSend

Length of output: 41


🏁 Script executed:

# First, let's find the actual env schema/configuration file
fd -e js -e ts -e json apps/web/src/ | grep -i env | head -20

Repository: usesend/useSend

Length of output: 417


🏁 Script executed:

# Let's examine the credentials.ts file in full
cat -n apps/web/src/server/aws/credentials.ts

Repository: usesend/useSend

Length of output: 713


🏁 Script executed:

# Check the env.js or env schema structure
fd -type f -name "env*" apps/web/src/ | head -10

Repository: usesend/useSend

Length of output: 230


🏁 Script executed:

# Find env configuration files more carefully
find apps/web/src -name "env*" -type f | head -20

Repository: usesend/useSend

Length of output: 79


🏁 Script executed:

# Also search for where env is exported from
rg -l "export.*env" apps/web/src --type ts --type js | head -10

Repository: usesend/useSend

Length of output: 196


🏁 Script executed:

# Look for AWS configuration in existing code
rg "AWS_ACCESS_KEY_ID|AWS_SECRET_ACCESS_KEY" apps/web/src --type ts --type js -A 2 -B 2

Repository: usesend/useSend

Length of output: 2484


🏁 Script executed:

# Read the full env.js file
cat -n apps/web/src/env.js

Repository: usesend/useSend

Length of output: 7193


🏁 Script executed:

# Check AWS SDK documentation expectations for sessionToken# Look for any existing usage or patterns of sessionToken in the codebase
rg "sessionToken|session_token" apps/web --type ts --type js

Repository: usesend/useSend

Length of output: 41


🏁 Script executed:

# Check how AWS SDK is being used for SES and SNS
cat -n apps/web/src/server/aws/ses.ts | head -50

Repository: usesend/useSend

Length of output: 1938


🏁 Script executed:

# Look for any auth-related issues or comments in AWS files
rg "auth|sign|credential|temporary|session" apps/web/src/server/aws/ --type ts -i

Repository: usesend/useSend

Length of output: 781


🏁 Script executed:

# Check AWS SDK version/package being used
rg "@aws-sdk|aws-sdk" apps/web/package.json

Repository: usesend/useSend

Length of output: 265


Add AWS_SESSION_TOKEN support to credentials helper for temporary AWS credentials.

AWS SDK v3 requires sessionToken when using temporary credentials (from STS, IAM roles, or AssumeRole). The current implementation only handles accessKeyId and secretAccessKey, which works for long-lived IAM credentials but will fail with temporary credentials.

Add AWS_SESSION_TOKEN as an optional environment variable in env.js schema and runtimeEnv, then conditionally include it in the returned credentials object in credentials.ts. Update test setup and .env.example files as needed.

Suggested patch
 export function getAwsCredentialOptions() {
const hasKey = !!env.AWS_ACCESS_KEY_ID;
const hasSecret = !!env.AWS_SECRET_ACCESS_KEY;
+ const hasSessionToken = !!env.AWS_SESSION_TOKEN;
if (hasKey !== hasSecret) {
throw new Error(
"AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must both be set or both be omitted"
);
}
if (hasKey) {
return {
credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID!,
secretAccessKey: env.AWS_SECRET_ACCESS_KEY!,
+ ...(hasSessionToken ? { sessionToken: env.AWS_SESSION_TOKEN! } : {}),
},
};
}
return {};
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/web/src/server/aws/credentials.ts` around lines 4 - 19, The credentials
helper currently only returns accessKeyId and secretAccessKey, which breaks
temporary AWS creds; add support for AWS_SESSION_TOKEN by adding
AWS_SESSION_TOKEN to your env.js schema and runtimeEnv, then update the return
object in apps/web/src/server/aws/credentials.ts to conditionally include
sessionToken (e.g., when env.AWS_SESSION_TOKEN is present, add
credentials.sessionToken = env.AWS_SESSION_TOKEN) alongside accessKeyId and
secretAccessKey, and update test fixtures and .env.example to include an
optional AWS_SESSION_TOKEN entry so temporary credential flows are exercised.

@KMKoushik

Copy link
Copy Markdown
Member

merged with some changes in #401. ty

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feat: Avoid hardcoding AWS credentials & support standard AWS env variables

3 participants

@purva-8@KMKoushik