Skip to content

Commit

Permalink
Revert "fix: botocore session cache across samcli (#1693)"
Browse files Browse the repository at this point in the history
This reverts commit 2d71af8.
  • Loading branch information
sriram-mv committed Jan 7, 2020
1 parent 916be85 commit b8adf29
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 134 deletions.
117 changes: 0 additions & 117 deletions designs/botocore_sessions.md

This file was deleted.

10 changes: 1 addition & 9 deletions samcli/cli/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
Context information passed to each CLI command
"""

import logging
import uuid

import logging
import boto3
import botocore
import botocore.session
from botocore import credentials
import click

from samcli.commands.exceptions import CredentialsError
Expand Down Expand Up @@ -147,11 +144,6 @@ def _refresh_session(self):
"""
try:
boto3.setup_default_session(region_name=self._aws_region, profile_name=self._aws_profile)
# get botocore session and setup caching for MFA based
boto3.DEFAULT_SESSION._session.get_component("credential_provider").get_provider( # pylint: disable=W0212
"assume-role"
).cache = credentials.JSONFileCache()

except botocore.exceptions.ProfileNotFound as ex:
raise CredentialsError(str(ex))

Expand Down
6 changes: 4 additions & 2 deletions samcli/commands/deploy/deploy_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ def run(self):
template_size = os.path.getsize(self.template_file)
if template_size > 51200 and not self.s3_bucket:
raise deploy_exceptions.DeployBucketRequiredError()
cloudformation_client = boto3.client("cloudformation", region_name=self.region if self.region else None)

session = boto3.Session(profile_name=self.profile if self.profile else None)
cloudformation_client = session.client("cloudformation", region_name=self.region if self.region else None)

s3_client = None
if self.s3_bucket:
s3_client = boto3.client("s3", region_name=self.region if self.region else None)
s3_client = session.client("s3", region_name=self.region if self.region else None)

self.s3_uploader = S3Uploader(s3_client, self.s3_bucket, self.s3_prefix, self.kms_key_id, self.force_upload)

Expand Down
3 changes: 2 additions & 1 deletion samcli/commands/package/package_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def __exit__(self, *args):

def run(self):

s3_client = boto3.client(
session = boto3.Session(profile_name=self.profile if self.profile else None)
s3_client = session.client(
"s3", config=Config(signature_version="s3v4", region_name=self.region if self.region else None)
)

Expand Down
4 changes: 3 additions & 1 deletion samcli/lib/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
from samcli.cli.global_config import GlobalConfig
from samcli.commands.exceptions import UserException, CredentialsError, RegionError


SAM_CLI_STACK_NAME = "aws-sam-cli-managed-default"
LOG = logging.getLogger(__name__)


def manage_stack(profile, region):
try:
cloudformation_client = boto3.client("cloudformation", config=Config(region_name=region if region else None))
session = boto3.Session(profile_name=profile if profile else None)
cloudformation_client = session.client("cloudformation", config=Config(region_name=region if region else None))
except NoCredentialsError:
raise CredentialsError(
"Error Setting Up Managed Stack Client: Unable to resolve credentials for the AWS SDK for Python client. Please see their documentation for options to pass in credentials: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html"
Expand Down
12 changes: 8 additions & 4 deletions tests/unit/lib/bootstrap/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ def _stubbed_cf_client(self):
cf = botocore.session.get_session().create_client("cloudformation", region_name="us-west-2")
return [cf, Stubber(cf)]

@patch("boto3.client")
@patch("boto3.Session")
def test_client_missing_credentials(self, boto_mock):
boto_mock.side_effect = NoCredentialsError()
session_mock = Mock()
session_mock.client.side_effect = NoCredentialsError()
boto_mock.return_value = session_mock
with self.assertRaises(CredentialsError):
manage_stack("testprofile", "fake-region")

@patch("boto3.client")
@patch("boto3.Session")
def test_client_missing_region(self, boto_mock):
boto_mock.side_effect = NoRegionError()
session_mock = Mock()
session_mock.client.side_effect = NoRegionError()
boto_mock.return_value = session_mock
with self.assertRaises(RegionError):
manage_stack("testprofile", "fake-region")

Expand Down

0 comments on commit b8adf29

Please sign in to comment.