Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hip-steaks-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"sst": patch
---

Fix sst bind to skip empty env vars so local env values aren’t overwritten
24 changes: 18 additions & 6 deletions packages/sst/src/cli/commands/bind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type BIND_REASON =
| "secrets_updated"
| "iam_expired";

class MetadataNotFoundError extends Error {}
class MetadataOutdatedError extends Error {}
class MetadataNotFoundError extends Error { }
class MetadataOutdatedError extends Error { }

export const bind = (program: Program) =>
program
Expand Down Expand Up @@ -183,8 +183,8 @@ export const bind = (program: Program) =>
const siteConfig = ssrSite
? await getSsrSiteMetadata()
: staticSite
? await getStaticSiteMetadata()
: await getServiceMetadata();
? await getStaticSiteMetadata()
: await getServiceMetadata();

// Handle rebind due to metadata updated
if (reason === "metadata_updated") {
Expand All @@ -204,7 +204,7 @@ export const bind = (program: Program) =>
(await getLiveIamCredentials(siteConfig.role))) ||
(await getLocalIamCredentials());
await runCommand({
...siteConfig.envs,
...stripEmptyEnvValues(siteConfig.envs),
...credentials,
});
}
Expand All @@ -228,7 +228,7 @@ export const bind = (program: Program) =>

const { Config } = await import("../../config.js");
await runCommand({
...constructEnvs,
...stripEmptyEnvValues(constructEnvs),
...(await Config.env()),
...(await getLocalIamCredentials()),
});
Expand All @@ -242,6 +242,18 @@ export const bind = (program: Program) =>
});
}

function stripEmptyEnvValues(
envs: Record<string, string | undefined | null> | undefined
): Record<string, string> {
const result: Record<string, string> = {};
for (const [key, value] of Object.entries(envs ?? {})) {
if (value !== undefined && value !== null && value !== "") {
result[key] = value;
}
}
return result;
}

async function getSsrSiteMetadata() {
const [
{ metadataForStack },
Expand Down