cloud-foundry 0.2.3__tar.gz → 0.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/PKG-INFO +1 -2
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/__init__.py +2 -1
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/pulumi/function.py +80 -2
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/pulumi/idle_reaper.py +71 -3
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/pulumi/python_function.py +3 -0
- cloud_foundry-0.3.1/cloud_foundry/utils/idle_reaper_client.py +63 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/pyproject.toml +18 -2
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/.gitignore +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/LICENSE +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/README.md +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/archive_builder.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/mail_publisher.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/pulumi/__init__.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/pulumi/api_waf.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/pulumi/cdn.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/pulumi/cdn_api_origin.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/pulumi/cdn_site_origin.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/pulumi/connection_store.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/pulumi/custom_domain.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/pulumi/document_repository.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/pulumi/domain.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/pulumi/publisher.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/pulumi/queue.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/pulumi/rest_api.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/pulumi/site_bucket.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/pulumi/topic.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/pulumi/ui_publisher.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/pulumi/websocket_api.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/pulumi/websocket_function.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/python_archive_builder.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/services/authorization_api/security_lambda.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/services/mail_publisher.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/utils/aws_openapi_editor.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/utils/hash_comparator.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/utils/logger.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/utils/names.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/utils/openapi_editor.py +0 -0
- {cloud_foundry-0.2.3 → cloud_foundry-0.3.1}/cloud_foundry/utils/websocket_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cloud-foundry
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: cloud-foundry is a curated set of cloud components that can be used to assemble cloud-based applications.
|
|
5
5
|
Project-URL: Documentation, https://github.com/DanRepik/cloud-foundry
|
|
6
6
|
Project-URL: Source, https://github.com/DanRepik/cloud-foundry
|
|
@@ -17,7 +17,6 @@ Provides-Extra: dev
|
|
|
17
17
|
Requires-Dist: black>=23.0.0; extra == 'dev'
|
|
18
18
|
Requires-Dist: build; extra == 'dev'
|
|
19
19
|
Requires-Dist: docker; extra == 'dev'
|
|
20
|
-
Requires-Dist: fixture-foundry; extra == 'dev'
|
|
21
20
|
Requires-Dist: flake8; extra == 'dev'
|
|
22
21
|
Requires-Dist: flit>=3.9; extra == 'dev'
|
|
23
22
|
Requires-Dist: isort>=5.12.0; extra == 'dev'
|
|
@@ -22,8 +22,9 @@ from cloud_foundry.pulumi.domain import domain # noqa: F401
|
|
|
22
22
|
from cloud_foundry.pulumi.queue import queue # noqa: F401
|
|
23
23
|
from cloud_foundry.pulumi.topic import topic # noqa: F401
|
|
24
24
|
from cloud_foundry.pulumi.idle_reaper import attach_idle_reaper # noqa: F401
|
|
25
|
+
from cloud_foundry.utils.idle_reaper_client import request_mapping_enable # noqa: F401
|
|
25
26
|
|
|
26
27
|
from cloud_foundry.utils.names import resource_id # noqa: F401
|
|
27
28
|
from cloud_foundry.utils.names import project_slug # noqa: F401
|
|
28
29
|
|
|
29
|
-
version = "0.
|
|
30
|
+
version = "0.3.1"
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# function.py
|
|
2
|
+
import os
|
|
2
3
|
import platform
|
|
3
4
|
from typing import Any, Optional, TypeAlias, Union
|
|
4
5
|
|
|
@@ -14,6 +15,20 @@ PolicyStatement: TypeAlias = dict[str, Any] | str
|
|
|
14
15
|
PolicyStatements: TypeAlias = list[PolicyStatement]
|
|
15
16
|
PolicyStatementsInput: TypeAlias = pulumi.Input[PolicyStatements]
|
|
16
17
|
|
|
18
|
+
# AWS's documented cap for Lambda's direct/inline code upload (the
|
|
19
|
+
# CreateFunction/UpdateFunctionCode API's request-body limit for a
|
|
20
|
+
# base64-encoded zip passed as `code=`). S3-based upload (code_bucket=)
|
|
21
|
+
# raises this to 250MB unzipped.
|
|
22
|
+
DIRECT_UPLOAD_SIZE_LIMIT = 50 * 1024 * 1024
|
|
23
|
+
|
|
24
|
+
CodeBucketInput = Union[str, pulumi.Output[str], "aws.s3.BucketV2", "aws.s3.Bucket"]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _code_bucket_name(bucket: CodeBucketInput) -> pulumi.Input[str]:
|
|
28
|
+
if isinstance(bucket, (aws.s3.BucketV2, aws.s3.Bucket)):
|
|
29
|
+
return bucket.bucket
|
|
30
|
+
return bucket
|
|
31
|
+
|
|
17
32
|
|
|
18
33
|
class Function(pulumi.ComponentResource):
|
|
19
34
|
lambda_: aws.lambda_.Function
|
|
@@ -32,6 +47,7 @@ class Function(pulumi.ComponentResource):
|
|
|
32
47
|
environment: dict[str, Union[str, pulumi.Output[str]]] = None,
|
|
33
48
|
policy_statements: Optional[PolicyStatementsInput] = None,
|
|
34
49
|
vpc_config: Optional[dict] = None,
|
|
50
|
+
code_bucket: Optional[CodeBucketInput] = None,
|
|
35
51
|
opts=None,
|
|
36
52
|
):
|
|
37
53
|
super().__init__("cloud_foundry:lambda:Function", name, {}, opts)
|
|
@@ -47,6 +63,7 @@ class Function(pulumi.ComponentResource):
|
|
|
47
63
|
self.timeout = timeout
|
|
48
64
|
self.policy_statements = policy_statements or []
|
|
49
65
|
self.vpc_config = vpc_config or {}
|
|
66
|
+
self.code_bucket = code_bucket
|
|
50
67
|
self.function_name = f"{pulumi.get_project()}-{pulumi.get_stack()}-{self.name}"
|
|
51
68
|
self.log_group_name = f"/aws/lambda/{self.function_name}"
|
|
52
69
|
# Validate that the environment is a dictionary with string
|
|
@@ -143,9 +160,61 @@ class Function(pulumi.ComponentResource):
|
|
|
143
160
|
|
|
144
161
|
log.info("Environment args type: %s", type(environment_args))
|
|
145
162
|
|
|
163
|
+
code_depends_on = []
|
|
164
|
+
if self.code_bucket is not None:
|
|
165
|
+
# Explicit opt-in: upload via S3 instead of passing the zip
|
|
166
|
+
# inline. Keyed by content hash so unchanged code across
|
|
167
|
+
# deploys reuses the same object instead of re-uploading.
|
|
168
|
+
#
|
|
169
|
+
# hash is required here (unlike the inline path below, which
|
|
170
|
+
# doesn't need it): without a real value, the key degrades to
|
|
171
|
+
# "name/None.zip" -- every version collides on the same S3
|
|
172
|
+
# object, and source_code_hash=None below means Pulumi's own
|
|
173
|
+
# diff sees no change between deploys either, so a later code
|
|
174
|
+
# change wouldn't even trigger a Lambda update.
|
|
175
|
+
if not self.hash:
|
|
176
|
+
raise ValueError(
|
|
177
|
+
f"Function '{self.name}': code_bucket requires hash= "
|
|
178
|
+
f"(used for both the S3 object key and Lambda change "
|
|
179
|
+
f"detection). python_function() always supplies this; "
|
|
180
|
+
f"only the lower-level Function()/function() API can "
|
|
181
|
+
f"omit it."
|
|
182
|
+
)
|
|
183
|
+
bucket_name = _code_bucket_name(self.code_bucket)
|
|
184
|
+
code_object = aws.s3.BucketObjectv2(
|
|
185
|
+
f"{self.name}-code",
|
|
186
|
+
bucket=bucket_name,
|
|
187
|
+
key=f"{self.name}/{self.hash}.zip",
|
|
188
|
+
source=pulumi.FileAsset(self.archive_location),
|
|
189
|
+
opts=pulumi.ResourceOptions(parent=self),
|
|
190
|
+
)
|
|
191
|
+
code_args = {"s3_bucket": bucket_name, "s3_key": code_object.key}
|
|
192
|
+
code_depends_on = [code_object]
|
|
193
|
+
else:
|
|
194
|
+
# Pulumi resource creation is async (the actual CreateFunction
|
|
195
|
+
# call happens in the provider plugin during apply, not
|
|
196
|
+
# synchronously here), so AWS's RequestEntityTooLargeException
|
|
197
|
+
# can't be caught with a plain try/except around the resource
|
|
198
|
+
# declaration below -- check the size ourselves first instead,
|
|
199
|
+
# for the same practical effect: a clear error at plan time
|
|
200
|
+
# instead of a cryptic one after an apply attempt.
|
|
201
|
+
archive_size = os.path.getsize(self.archive_location)
|
|
202
|
+
if archive_size > DIRECT_UPLOAD_SIZE_LIMIT:
|
|
203
|
+
raise ValueError(
|
|
204
|
+
f"Lambda deployment package for '{self.name}' is "
|
|
205
|
+
f"{archive_size / (1024 * 1024):.1f}MB, over AWS's "
|
|
206
|
+
f"~50MB limit for direct/inline upload (the "
|
|
207
|
+
f"CreateFunction API's request-body cap). Pass "
|
|
208
|
+
f"code_bucket=<an aws.s3.BucketV2/Bucket or bucket "
|
|
209
|
+
f"name> to python_function()/Function() to upload it "
|
|
210
|
+
f"via S3 instead, which supports packages up to "
|
|
211
|
+
f"250MB unzipped."
|
|
212
|
+
)
|
|
213
|
+
code_args = {"code": pulumi.FileArchive(self.archive_location)}
|
|
214
|
+
|
|
146
215
|
self.lambda_ = aws.lambda_.Function(
|
|
147
216
|
f"{self.name}-function",
|
|
148
|
-
|
|
217
|
+
**code_args,
|
|
149
218
|
name=self.function_name,
|
|
150
219
|
role=execution_role.arn,
|
|
151
220
|
memory_size=self.memory_size,
|
|
@@ -157,7 +226,8 @@ class Function(pulumi.ComponentResource):
|
|
|
157
226
|
environment=environment_args,
|
|
158
227
|
vpc_config=vpc_config_args,
|
|
159
228
|
opts=pulumi.ResourceOptions(
|
|
160
|
-
depends_on=[execution_role, log_group],
|
|
229
|
+
depends_on=[execution_role, log_group] + code_depends_on,
|
|
230
|
+
parent=self,
|
|
161
231
|
),
|
|
162
232
|
)
|
|
163
233
|
|
|
@@ -351,6 +421,7 @@ def function(
|
|
|
351
421
|
environment: dict[str, str] = None,
|
|
352
422
|
policy_statements: list = None,
|
|
353
423
|
vpc_config: dict = None,
|
|
424
|
+
code_bucket: Optional[CodeBucketInput] = None,
|
|
354
425
|
opts=None,
|
|
355
426
|
) -> Function:
|
|
356
427
|
"""
|
|
@@ -370,6 +441,12 @@ def function(
|
|
|
370
441
|
policy_statements (list): IAM policy statements for the
|
|
371
442
|
Lambda function.
|
|
372
443
|
vpc_config (dict): VPC configuration for the Lambda function.
|
|
444
|
+
code_bucket: An aws.s3.BucketV2/Bucket or bucket name to upload the
|
|
445
|
+
code archive through instead of passing it inline. Required if
|
|
446
|
+
the archive exceeds AWS's ~50MB direct-upload limit -- omitting
|
|
447
|
+
it in that case raises a ValueError explaining this parameter,
|
|
448
|
+
rather than letting the deploy fail on AWS's own cryptic
|
|
449
|
+
RequestEntityTooLargeException.
|
|
373
450
|
opts: Pulumi resource options.
|
|
374
451
|
|
|
375
452
|
Returns:
|
|
@@ -386,6 +463,7 @@ def function(
|
|
|
386
463
|
environment=environment,
|
|
387
464
|
policy_statements=policy_statements,
|
|
388
465
|
vpc_config=vpc_config,
|
|
466
|
+
code_bucket=code_bucket,
|
|
389
467
|
opts=opts,
|
|
390
468
|
)
|
|
391
469
|
|
|
@@ -4,8 +4,21 @@ civarai-evidence/infra/shared-foundation). Queue owners call
|
|
|
4
4
|
`attach_idle_reaper` after subscribing their Lambda to their queue so the
|
|
5
5
|
reaper auto-disables the event source mapping once the queue is fully
|
|
6
6
|
drained -- avoiding empty-poll SQS request volume from a mapping nobody
|
|
7
|
-
remembered to turn off.
|
|
8
|
-
|
|
7
|
+
remembered to turn off.
|
|
8
|
+
|
|
9
|
+
Re-enabling is still each producer's own responsibility -- the reaper never
|
|
10
|
+
does it on its own initiative -- but `attach_idle_reaper` now also wires an
|
|
11
|
+
on-demand path for that: a second EventRule, scoped to this consumer's
|
|
12
|
+
queue, that matches a custom "EnableMapping" event and re-enables the
|
|
13
|
+
mapping unconditionally (no drain/depth check needed for that direction).
|
|
14
|
+
Producers trigger it via `cloud_foundry.utils.idle_reaper_client.
|
|
15
|
+
request_mapping_enable(queue_url)` -- see that module's docstring for the
|
|
16
|
+
tradeoff between importing it from `cloud_foundry` (pulls in pulumi/
|
|
17
|
+
pulumi-aws transitively, same as any other cloud_foundry import) versus
|
|
18
|
+
inlining its few lines directly in a dependency-sensitive Lambda. Producers
|
|
19
|
+
only ever need the queue URL they already have to know to call SendMessage
|
|
20
|
+
in the first place; they never need the event source mapping's UUID or the
|
|
21
|
+
reaper's function/role names.
|
|
9
22
|
|
|
10
23
|
The reaper's function name and IAM role name are computed deterministically
|
|
11
24
|
via cloud_foundry's own naming convention (see
|
|
@@ -48,9 +61,11 @@ def attach_idle_reaper(
|
|
|
48
61
|
reaper_role_name: str,
|
|
49
62
|
resource_prefix: str,
|
|
50
63
|
interval_minutes: int = 10,
|
|
64
|
+
event_bus_name: str = "default",
|
|
51
65
|
opts: Optional[ResourceOptions] = None,
|
|
52
66
|
) -> None:
|
|
53
|
-
"""Schedule the shared idle-esm-reaper Lambda against one queue/mapping
|
|
67
|
+
"""Schedule the shared idle-esm-reaper Lambda against one queue/mapping,
|
|
68
|
+
and wire an on-demand re-enable path for the same mapping.
|
|
54
69
|
|
|
55
70
|
Args:
|
|
56
71
|
queue: The cloud_foundry Queue (or anything exposing `.arn`/`.url`)
|
|
@@ -65,6 +80,11 @@ def attach_idle_reaper(
|
|
|
65
80
|
resource_prefix: Unique prefix for this consumer's Pulumi resource
|
|
66
81
|
names, e.g. `resource_id("workflow")`.
|
|
67
82
|
interval_minutes: How often the reaper checks this queue.
|
|
83
|
+
event_bus_name: EventBridge bus the on-demand enable rule listens
|
|
84
|
+
on. Must match the bus `idle_reaper_client.request_mapping_enable`
|
|
85
|
+
callers publish to -- both default to the account's "default"
|
|
86
|
+
bus, so this only needs to change if a consumer already uses a
|
|
87
|
+
dedicated custom bus.
|
|
68
88
|
opts: Pulumi ResourceOptions (e.g. `parent=`) applied to every
|
|
69
89
|
resource created here.
|
|
70
90
|
"""
|
|
@@ -138,3 +158,51 @@ def attach_idle_reaper(
|
|
|
138
158
|
source_arn=rule.arn,
|
|
139
159
|
opts=opts,
|
|
140
160
|
)
|
|
161
|
+
|
|
162
|
+
# On-demand enable path. Scoped to this consumer's own queue URL, so a
|
|
163
|
+
# request_mapping_enable() call from any producer only ever wakes the
|
|
164
|
+
# one EventRule whose queue_url it matches -- unmatched events are
|
|
165
|
+
# dropped by EventBridge, no coordination needed across consumers.
|
|
166
|
+
enable_rule = aws.cloudwatch.EventRule(
|
|
167
|
+
f"{resource_prefix}-idle-reaper-enable",
|
|
168
|
+
name=_aws_name(resource_prefix, "idle-reaper-enable", 64),
|
|
169
|
+
event_bus_name=event_bus_name,
|
|
170
|
+
event_pattern=queue.url.apply(
|
|
171
|
+
lambda queue_url: json.dumps(
|
|
172
|
+
{
|
|
173
|
+
"source": ["cloud_foundry.idle_reaper"],
|
|
174
|
+
"detail-type": ["EnableMapping"],
|
|
175
|
+
"detail": {"queue_url": [queue_url]},
|
|
176
|
+
}
|
|
177
|
+
)
|
|
178
|
+
),
|
|
179
|
+
opts=opts,
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
aws.cloudwatch.EventTarget(
|
|
183
|
+
f"{resource_prefix}-idle-reaper-enable-target",
|
|
184
|
+
target_id=_aws_name(resource_prefix, "idle-reaper-enable-tgt", 64),
|
|
185
|
+
rule=enable_rule.name,
|
|
186
|
+
event_bus_name=event_bus_name,
|
|
187
|
+
arn=reaper_arn,
|
|
188
|
+
input=event_source_mapping.id.apply(
|
|
189
|
+
lambda uuid: json.dumps(
|
|
190
|
+
{
|
|
191
|
+
"action": "enable",
|
|
192
|
+
"queue_name": resource_prefix,
|
|
193
|
+
"event_source_mapping_uuid": uuid,
|
|
194
|
+
}
|
|
195
|
+
)
|
|
196
|
+
),
|
|
197
|
+
opts=opts,
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
aws.lambda_.Permission(
|
|
201
|
+
f"{resource_prefix}-idle-reaper-enable-invoke",
|
|
202
|
+
statement_id=_aws_name(resource_prefix, "idle-reaper-enable-invoke", 100),
|
|
203
|
+
action="lambda:InvokeFunction",
|
|
204
|
+
function=reaper_function_name,
|
|
205
|
+
principal="events.amazonaws.com",
|
|
206
|
+
source_arn=enable_rule.arn,
|
|
207
|
+
opts=opts,
|
|
208
|
+
)
|
|
@@ -6,6 +6,7 @@ from cloud_foundry.utils.logger import logger
|
|
|
6
6
|
|
|
7
7
|
from cloud_foundry.python_archive_builder import PythonArchiveBuilder
|
|
8
8
|
from cloud_foundry.pulumi.function import (
|
|
9
|
+
CodeBucketInput,
|
|
9
10
|
Function,
|
|
10
11
|
PolicyStatementsInput,
|
|
11
12
|
default_lambda_architecture,
|
|
@@ -27,6 +28,7 @@ def python_function(
|
|
|
27
28
|
vpc_config: Optional[dict] = None,
|
|
28
29
|
runtime: Optional[str] = None,
|
|
29
30
|
architecture: Optional[str] = None,
|
|
31
|
+
code_bucket: Optional[CodeBucketInput] = None,
|
|
30
32
|
opts=None,
|
|
31
33
|
) -> Function:
|
|
32
34
|
resolved_architecture = architecture or default_lambda_architecture()
|
|
@@ -49,5 +51,6 @@ def python_function(
|
|
|
49
51
|
vpc_config=vpc_config,
|
|
50
52
|
runtime=runtime,
|
|
51
53
|
architectures=[resolved_architecture],
|
|
54
|
+
code_bucket=code_bucket,
|
|
52
55
|
opts=opts,
|
|
53
56
|
)
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""Runtime-side client for cloud_foundry's idle-ESM-reaper "enable" event.
|
|
2
|
+
|
|
3
|
+
Companion to cloud_foundry.pulumi.idle_reaper.attach_idle_reaper -- unlike
|
|
4
|
+
that module (which authors Pulumi infrastructure at `pulumi up` time), this
|
|
5
|
+
one runs inside whatever already-deployed producer/ingestion code sends
|
|
6
|
+
messages into a reaper-managed queue. This module itself only needs boto3,
|
|
7
|
+
but importing it as `cloud_foundry.utils.idle_reaper_client` still runs
|
|
8
|
+
`cloud_foundry/__init__.py` first (normal Python package behavior), which
|
|
9
|
+
pulls in pulumi/pulumi-aws as transitive dependencies of the `cloud-foundry`
|
|
10
|
+
package regardless. A producer that wants to avoid carrying those into a
|
|
11
|
+
lightweight Lambda can inline the few lines of `request_mapping_enable`
|
|
12
|
+
below instead of depending on `cloud-foundry` for just this.
|
|
13
|
+
|
|
14
|
+
A producer that wants the shared reaper to keep its queue's mapping alive
|
|
15
|
+
calls `request_mapping_enable(queue_url)` before sending. It never needs to
|
|
16
|
+
know the event source mapping's UUID, the reaper's function/role names, or
|
|
17
|
+
any Pulumi-side resource naming scheme -- only the queue URL it already has
|
|
18
|
+
to know to call SendMessage in the first place.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
import json
|
|
22
|
+
from typing import Optional
|
|
23
|
+
|
|
24
|
+
import boto3
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def request_mapping_enable(
|
|
28
|
+
queue_url: str,
|
|
29
|
+
*,
|
|
30
|
+
event_bus_name: str = "default",
|
|
31
|
+
region_name: Optional[str] = None,
|
|
32
|
+
) -> None:
|
|
33
|
+
"""Ask the shared idle-ESM-reaper to re-enable the mapping for `queue_url`.
|
|
34
|
+
|
|
35
|
+
Fire-and-forget: puts a custom event on the given EventBridge bus. Any
|
|
36
|
+
`attach_idle_reaper` consumer whose queue matches `queue_url` picks it
|
|
37
|
+
up via its own scoped EventRule and re-enables its own mapping --
|
|
38
|
+
nothing here needs to know which consumer that is, or whether one
|
|
39
|
+
exists at all (an unmatched event is simply dropped by EventBridge, so
|
|
40
|
+
calling this for a queue that isn't reaper-managed is a harmless no-op).
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
queue_url: The SQS queue URL the caller is about to send messages
|
|
44
|
+
to -- must match the `queue_url` the mapping owner's
|
|
45
|
+
`attach_idle_reaper()` call was scoped to.
|
|
46
|
+
event_bus_name: EventBridge bus to publish to. Must match the
|
|
47
|
+
`event_bus_name` the mapping owner passed to
|
|
48
|
+
`attach_idle_reaper()` -- both default to the account's
|
|
49
|
+
"default" bus.
|
|
50
|
+
region_name: AWS region for the EventBridge client, if not picked
|
|
51
|
+
up from the caller's ambient environment/credentials.
|
|
52
|
+
"""
|
|
53
|
+
events = boto3.client("events", region_name=region_name)
|
|
54
|
+
events.put_events(
|
|
55
|
+
Entries=[
|
|
56
|
+
{
|
|
57
|
+
"EventBusName": event_bus_name,
|
|
58
|
+
"Source": "cloud_foundry.idle_reaper",
|
|
59
|
+
"DetailType": "EnableMapping",
|
|
60
|
+
"Detail": json.dumps({"queue_url": queue_url}),
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
)
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
# src/pyproject.toml
|
|
2
2
|
|
|
3
3
|
[build-system]
|
|
4
|
-
|
|
4
|
+
# hatchling>=1.32.0 emits Metadata-Version: 2.5, which PyPI's Warehouse
|
|
5
|
+
# rejects outright with a 400 on every upload regardless of package
|
|
6
|
+
# version -- see https://github.com/pypi/warehouse/issues/19083 (open,
|
|
7
|
+
# unresolved). Pinned below that until Warehouse adds 2.5 support.
|
|
8
|
+
requires = ["hatchling>=1.0,<1.32.0"]
|
|
5
9
|
build-backend = "hatchling.build"
|
|
6
10
|
|
|
7
11
|
[project]
|
|
@@ -45,10 +49,22 @@ dev = [
|
|
|
45
49
|
"requests",
|
|
46
50
|
"python-dotenv",
|
|
47
51
|
"pyjwt",
|
|
48
|
-
"fixture_foundry",
|
|
49
52
|
"psycopg2-binary",
|
|
50
53
|
]
|
|
51
54
|
|
|
55
|
+
# fixture_foundry is NOT listed above on purpose. PyPI's upload API rejects
|
|
56
|
+
# any package whose metadata declares a direct URL/VCS dependency, even one
|
|
57
|
+
# scoped to an optional extra -- so a git-pinned entry here would block
|
|
58
|
+
# every future `cloud-foundry` publish, not just fail quietly. Published
|
|
59
|
+
# fixture_foundry (still 0.2.4 as of this pin) has stale calls into its own
|
|
60
|
+
# context.py API that crash test collection (see DanRepik/fixture_foundry#4,
|
|
61
|
+
# fixed on branch fix/fixtures-stale-teardown-calls but not yet released).
|
|
62
|
+
# Install it separately before running the integration test suite:
|
|
63
|
+
# pip install git+https://github.com/DanRepik/fixture_foundry.git@fix/fixtures-stale-teardown-calls
|
|
64
|
+
# CI does this as its own step -- see .github/workflows/pytest.yml and
|
|
65
|
+
# publish.yml. Once a fixed version is published to PyPI, add a plain
|
|
66
|
+
# "fixture_foundry>=X.Y.Z" back to the dev extra above and drop this note.
|
|
67
|
+
|
|
52
68
|
[tool.pytest.ini_options]
|
|
53
69
|
pythonpath = [".."]
|
|
54
70
|
testpaths = ["tests"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|