8000 Keep discard logic · localstack/localstack@787c113 · GitHub
[go: up one dir, main page]

Skip to content

Commit 787c113

Browse files
Keep discard logic
1 parent b7ca2ef commit 787c113

File tree

1 file changed

+16
-1
lines changed
  • localstack-core/localstack/runtime

1 file changed

+16
-1
lines changed

localstack-core/localstack/runtime/init.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ def run_stage(self, stage: Stage) -> List[Script]:
155155
for script in scripts:
156156
LOG.debug("Running %s script %s", script.stage, script.path)
157157

158+
env_original = os.environ.copy()
159+
158160
try:
159161
script.state = State.RUNNING
160162
runner = self.get_script_runner(script.path)
@@ -167,7 +169,20 @@ def run_stage(self, stage: Stage) -> List[Script]:
167169
LOG.error("Error while running script %s: %s", script, e)
168170
else:
169171
script.state = State.SUCCESSFUL
170-
172+
finally:
173+
# Discard env variables overridden in startup script that may cause side-effects
174+
for env_var in (
175+
"AWS_ACCESS_KEY_ID",
176+
"AWS_SECRET_ACCESS_KEY",
177+
"AWS_SESSION_TOKEN",
178+
"AWS_DEFAULT_REGION",
179+
"AWS_PROFILE",
180+
"AWS_REGION",
181+
):
182+
if env_var in env_original:
183+
os.environ[env_var] = env_original[env_var]
184+
else:
185+
os.environ.pop(env_var, None)
171186
finally:
172187
self.stage_completed[stage] = True
173188

0 commit comments

Comments
 (0)
0