Skip to content

Commit ccaedf2

Browse files
Merge branch 'master' into bump-moto-ext
2 parents 6979312 + f7890b2 commit ccaedf2

File tree

31 files changed

+543
-125
lines changed

31 files changed

+543
-125
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# java-builder: Stage to build a custom JRE (with jlink)
2-
FROM eclipse-temurin:11@sha256:1f62aaa9b6947e96189b4dbd14a7fc2a768914df3aefc9b0a1f7ec8a4dce8d6b as java-builder
2+
FROM eclipse-temurin:11@sha256:17571c4ae2936842c2b6547a382dd0fad3a4601294240a871a0282657f3e89db as java-builder
33

44
# create a custom, minimized JRE via jlink
55
RUN jlink --add-modules \

localstack/services/apigateway/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def __init__(self):
8383

8484
self.account.update(
8585
{
86-
"cloudwatchRoleArn": arns.role_arn(
86+
"cloudwatchRoleArn": arns.iam_role_arn(
8787
"api-gw-cw-role", DEFAULT_AWS_ACCOUNT_ID
8888
), # FIXME: account ID must be of the current store
8989
"throttleSettings": {"burstLimit": 1000, "rateLimit": 500},

localstack/services/cloudformation/engine/entities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def __init__(self, account_id: str, region_name: str, stack: Stack, params=None,
339339

340340
name = self.metadata["ChangeSetName"]
341341
if not self.metadata.get("ChangeSetId"):
342-
self.metadata["ChangeSetId"] = arns.cf_change_set_arn(
342+
self.metadata["ChangeSetId"] = arns.cloudformation_change_set_arn(
343343
name, change_set_id=short_uid(), account_id=account_id, region_name=region_name
344344
)
345345

localstack/services/cloudformation/models/ecr.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def fetch_state(self, stack_name, resources):
2525
repo_name = default_repos_per_stack.get(stack_name)
2626
if repo_name:
2727
return {
28-
"repositoryArn": arns.get_ecr_repository_arn(
28+
"repositoryArn": arns.ecr_repository_arn(
2929
repo_name, self.account_id, self.region_name
3030
),
3131
"registryId": self.account_id,
@@ -70,12 +70,12 @@ def _handle_result(
7070
resource: dict,
7171
):
7272
repo_name = resource["Properties"]["RepositoryName"]
73-
resource["PhysicalResourceId"] = arns.get_ecr_repository_arn(
73+
resource["PhysicalResourceId"] = arns.ecr_repository_arn(
7474
repo_name, account_id, region_name
7575
)
7676

7777
# add in some properties required for GetAtt and Ref
78-
resource["Properties"]["Arn"] = arns.get_ecr_repository_arn(
78+
resource["Properties"]["Arn"] = arns.ecr_repository_arn(
7979
repo_name, account_id, region_name
8080
)
8181
resource["Properties"]["RepositoryUri"] = "http://localhost:4566"

localstack/services/cloudformation/models/es.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def es_add_tags_params(
1616
resource: dict,
1717
stack_name: str,
1818
):
19-
es_arn = arns.es_domain_arn(properties.get("DomainName"), account_id, region_name)
19+
es_arn = arns.elasticsearch_domain_arn(properties.get("DomainName"), account_id, region_name)
2020
tags = properties.get("Tags", [])
2121
return {"ARN": es_arn, "TagList": tags}
2222

localstack/services/cloudformation/models/iam.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,9 @@ def _delete_params(
574574
resource: dict,
575575
stack_name: str,
576576
) -> dict:
577-
return {"PolicyArn": arns.policy_arn(properties["PolicyName"], account_id=account_id)}
577+
return {
578+
"PolicyArn": arns.iam_policy_arn(properties["PolicyName"], account_id=account_id)
579+
}
578580

579581
return {
580582
"create": {
@@ -601,7 +603,7 @@ def _filter(pols):
601603
groups = props.get("Groups", [])
602604
if managed_policy:
603605
result["policy"] = iam.get_policy(
604-
PolicyArn=arns.policy_arn(policy_name, account_id=account_id)
606+
PolicyArn=arns.iam_policy_arn(policy_name, account_id=account_id)
605607
)
606608
for role in roles:
607609
policies = (

localstack/services/cloudformation/models/opensearch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def opensearch_add_tags_params(
2424
resource: dict,
2525
stack_name: str,
2626
):
27-
es_arn = arns.es_domain_arn(properties.get("DomainName"), account_id, region_name)
27+
es_arn = arns.elasticsearch_domain_arn(properties.get("DomainName"), account_id, region_name)
2828
tags = properties.get("Tags", [])
2929
return {"ARN": es_arn, "TagList": tags}
3030

localstack/services/ecr/resource_providers/aws_ecr_repository.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def create(
9797
)
9898
model.update(
9999
{
100-
"Arn": arns.get_ecr_repository_arn(
100+
"Arn": arns.ecr_repository_arn(
101101
model["RepositoryName"], DEFAULT_AWS_ACCOUNT_ID, AWS_REGION_US_EAST_1
102102
),
103103
"RepositoryUri": "http://localhost:4566",

localstack/services/kinesis/provider.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def put_record(
151151
sequence_number_for_ordering: SequenceNumber = None,
152152
stream_arn: StreamARN = None,
153153
) -> PutRecordOutput:
154+
# TODO: Ensure use of `stream_arn` works. Currently kinesis-mock only works with ctx request account ID and region
154155
if random() < config.KINESIS_ERROR_PROBABILITY:
155156
raise ProvisionedThroughputExceededException(
156157
"Rate exceeded for shard X in stream Y under account Z."
@@ -166,6 +167,7 @@ def put_records(
166167
stream_name: StreamName = None,
167168
stream_arn: StreamARN = None,
168169
) -> PutRecordsOutput:
170+
# TODO: Ensure use of `stream_arn` works. Currently kinesis-mock only works with ctx request account ID and region
169171
if random() < config.KINESIS_ERROR_PROBABILITY:
170172
records_count = len(records) if records is not None else 0
171173
records = [

localstack/services/logs/provider.py

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from moto.logs.models import LogGroup as MotoLogGroup
1212
from moto.logs.models import LogStream as MotoLogStream
1313

14-
from localstack.aws.accounts import get_aws_account_id
1514
from localstack.aws.api import CommonServiceException, RequestContext, handler
1615
from localstack.aws.api.logs import (
1716
AmazonResourceName,
@@ -40,7 +39,7 @@
4039
from localstack.services.moto import call_moto
4140
from localstack.services.plugins import ServiceLifecycleHook
4241
from localstack.utils.aws import arns
43-
from localstack.utils.aws.arns import extract_region_from_arn
42+
from localstack.utils.aws.client_types import ServicePrincipal
4443
from localstack.utils.bootstrap import is_api_enabled
4544
from localstack.utils.common import is_number
4645
from localstack.utils.patch import patch
@@ -247,46 +246,61 @@ def moto_put_subscription_filter(fn, self, *args, **kwargs):
247246
role_arn = args[4]
248247

249248
log_group = self.groups.get(log_group_name)
249+
log_group_arn = arns.log_group_arn(log_group_name, self.account_id, self.region_name)
250250

251251
if not log_group:
252252
raise ResourceNotFoundException("The specified log group does not exist.")
253253

254+
arn_data = arns.parse_arn(destination_arn)
255+
256+
if role_arn:
257+
factory = connect_to.with_assumed_role(
258+
role_arn=role_arn, service_principal=ServicePrincipal.logs
259+
)
260+
else:
261+
factory = connect_to(aws_access_key_id=arn_data["account"], region_name=arn_data["region"])
262+
254263
if ":lambda:" in destination_arn:
255-
client = connect_to(region_name=extract_region_from_arn(destination_arn)).lambda_
256-
lambda_name = arns.lambda_function_name(destination_arn)
264+
client = factory.lambda_.request_metadata(
265+
source_arn=log_group_arn, service_principal=ServicePrincipal.logs
266+
)
257267
try:
258-
client.get_function(FunctionName=lambda_name)
268+
client.get_function(FunctionName=destination_arn)
259269
except Exception:
260270
raise InvalidParameterException(
261271
"destinationArn for vendor lambda cannot be used with roleArn"
262272
)
263273

264274
elif ":kinesis:" in destination_arn:
265-
client = connect_to().kinesis
275+
client = factory.kinesis.request_metadata(
276+
source_arn=log_group_arn, service_principal=ServicePrincipal.logs
277+
)
266278
stream_name = arns.kinesis_stream_name(destination_arn)
267279
try:
280+
# Kinesis-Local DescribeStream does not support StreamArn param, so use StreamName instead
268281
client.describe_stream(StreamName=stream_name)
269282
except Exception:
270283
raise InvalidParameterException(
271-
"Could not deliver test message to specified Kinesis stream. "
272-
"Check if the given kinesis stream is in ACTIVE state. "
284+
"Could not deliver message to specified Kinesis stream. "
285+
"Ensure that the Kinesis stream exists and is ACTIVE."
273286
)
274287

275288
elif ":firehose:" in destination_arn:
276-
client = connect_to().firehose
289+
client = factory.firehose.request_metadata(
290+
source_arn=log_group_arn, service_principal=ServicePrincipal.logs
291+
)
277292
firehose_name = arns.firehose_name(destination_arn)
278293
try:
279294
client.describe_delivery_stream(DeliveryStreamName=firehose_name)
280295
except Exception:
281296
raise InvalidParameterException(
282-
"Could not deliver test message to specified Firehose stream. "
283-
"Check if the given Firehose stream is in ACTIVE state."
297+
"Could not deliver message to specified Firehose stream. "
298+
"Ensure that the Firehose stream exists and is ACTIVE."
284299
)
285300

286301
else:
287-
service = arns.extract_service_from_arn(destination_arn)
288302
raise InvalidParameterException(
289-
f"PutSubscriptionFilter operation cannot work with destinationArn for vendor {service}"
303+
f"PutSubscriptionFilter operation cannot work with destinationArn for vendor {arn_data['service']}"
290304
)
291305

292306
if filter_pattern:
@@ -329,7 +343,7 @@ def moto_put_log_events(self: "MotoLogStream", log_events):
329343

330344
data = {
331345
"messageType": "DATA_MESSAGE",
332-
"owner": get_aws_account_id(),
346+
"owner": self.account_id, # AWS Account ID of the originating log data
333347
"logGroup": self.log_group.name,
334348
"logStream": self.log_stream_name,
335349
"subscriptionFilters": [subscription_filter.name],
@@ -342,20 +356,39 @@ def moto_put_log_events(self: "MotoLogStream", log_events):
342356
payload_gz_encoded = output.getvalue()
343357
event = {"awslogs": {"data": base64.b64encode(output.getvalue()).decode("utf-8")}}
344358

359+
log_group_arn = arns.log_group_arn(self.log_group.name, self.account_id, self.region)
360+
arn_data = arns.parse_arn(destination_arn)
361+
362+
if subscription_filter.role_arn:
363+
factory = connect_to.with_assumed_role(
364+
role_arn=subscription_filter.role_arn, service_principal=ServicePrincipal.logs
365+
)
366+
else:
367+
factory = connect_to(
368+
aws_access_key_id=arn_data["account"], region_name=arn_data["region"]
369+
)
370+
345371
if ":lambda:" in destination_arn:
346-
client = connect_to(region_name=extract_region_from_arn(destination_arn)).lambda_
347-
lambda_name = arns.lambda_function_name(destination_arn)
348-
client.invoke(FunctionName=lambda_name, Payload=json.dumps(event))
372+
client = factory.lambda_.request_metadata(
373+
source_arn=log_group_arn, service_principal=ServicePrincipal.logs
374+
)
375+
client.invoke(FunctionName=destination_arn, Payload=json.dumps(event))
376+
349377
if ":kinesis:" in destination_arn:
350-
client = connect_to().kinesis
378+
client = factory.kinesis.request_metadata(
379+
source_arn=log_group_arn, service_principal=ServicePrincipal.logs
380+
)
351381
stream_name = arns.kinesis_stream_name(destination_arn)
352382
client.put_record(
353383
StreamName=stream_name,
354384
Data=payload_gz_encoded,
355385
PartitionKey=self.log_group.name,
356386
)
387+
357388
if ":firehose:" in destination_arn:
358-
client = connect_to().firehose
389+
client = factory.firehose.request_metadata(
390+
source_arn=log_group_arn, service_principal=ServicePrincipal.logs
391+
)
359392
firehose_name = arns.firehose_name(destination_arn)
360393
client.put_record(
361394
DeliveryStreamName=firehose_name,

0 commit comments

Comments
 (0)