Skip to content

Commit 4cb46c0

Browse files
authored
fix: set mock credentials for emulator boto client (#8482)
1 parent 327a4a3 commit 4cb46c0

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

samcli/lib/clients/lambda_client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,15 @@ def create(cls, host: str = "localhost", port: int = 5000, region: str = "us-wes
5353
# Create a fresh botocore session
5454
session = botocore.session.Session()
5555

56-
# Create the boto3 client with custom service model using the fresh session
56+
# Create the boto3 client using the fresh session
5757
client = session.create_client(
5858
"lambda",
5959
endpoint_url=endpoint_url,
6060
region_name=region,
61+
# the emulator doesnt access any AWS resources,
62+
# but we need _some_ credentials to create a boto client
63+
aws_access_key_id="foo",
64+
aws_secret_access_key="bar",
6165
)
6266

6367
return cls(client)

tests/unit/lib/clients/test_lambda_client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ def test_create_default_parameters(self, mock_session_class):
4444
self.assertEqual(client.client, mock_client)
4545
mock_session_class.assert_called_once()
4646
mock_session.create_client.assert_called_once_with(
47-
"lambda", endpoint_url="http://localhost:5000", region_name="us-west-2"
47+
"lambda",
48+
endpoint_url="http://localhost:5000",
49+
region_name="us-west-2",
50+
aws_access_key_id="foo",
51+
aws_secret_access_key="bar",
4852
)
4953

5054
@patch("samcli.lib.clients.lambda_client.botocore.session.Session")
@@ -69,6 +73,8 @@ def test_create_custom_parameters(self, mock_session_class):
6973
"lambda",
7074
endpoint_url=f"http://{custom_host}:{custom_port}",
7175
region_name=custom_region,
76+
aws_access_key_id="foo",
77+
aws_secret_access_key="bar",
7278
)
7379

7480
@patch("samcli.lib.clients.lambda_client.botocore.session.Session")

0 commit comments

Comments
 (0)