diff --git a/runway/context/_base.py b/runway/context/_base.py index e319cbb24..cd286e325 100644 --- a/runway/context/_base.py +++ b/runway/context/_base.py @@ -163,13 +163,16 @@ def _inject_profile_credentials(self) -> None: # cov: ignore if self.current_aws_creds or not self.env.aws_profile: return - creds = ( - self.get_session(profile=self.env.aws_profile) - .get_credentials() - .get_frozen_credentials() - ) - - self.env.vars["AWS_ACCESS_KEY_ID"] = creds.access_key - self.env.vars["AWS_SECRET_ACCESS_KEY"] = creds.secret_key - if creds.token: - self.env.vars["AWS_SESSION_TOKEN"] = creds.token + try: + creds = self.get_session(profile=self.env.aws_profile).get_credentials() + if creds is not None: + frozen_creds = creds.get_frozen_credentials() + self.env.vars["AWS_ACCESS_KEY_ID"] = frozen_creds.access_key + self.env.vars["AWS_SECRET_ACCESS_KEY"] = frozen_creds.secret_key + if frozen_creds.token: + self.env.vars["AWS_SESSION_TOKEN"] = frozen_creds.token + else: + raise ValueError("Credentials could not be retrieved from the session.") + except Exception as e: + # Handle the exception as needed + self.logger.error("An error occurred: %s", e)