This repository has been archived by the owner on Nov 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Auto-generate processing table name
Work around <aws/aws-cdk#10952> by injecting `AWS_DEFAULT_REGION`. Set up production table using <pynamodb/PynamoDB#922 (comment)>.
- Loading branch information
Showing
17 changed files
with
189 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
"""Dataset object DynamoDB model.""" | ||
from enum import Enum | ||
from os import environ | ||
from typing import Type | ||
|
||
from pynamodb.attributes import UnicodeAttribute | ||
from pynamodb.models import Model | ||
|
||
from .resources import ResourceName | ||
from .parameter_store import ParameterName, get_param | ||
|
||
|
||
class ProcessingAssetType(Enum): | ||
DATA = "DATA_ITEM_INDEX" | ||
METADATA = "METADATA_ITEM_INDEX" | ||
|
||
|
||
class ProcessingAssetsModel(Model): | ||
class Meta: # pylint:disable=too-few-public-methods | ||
table_name = ResourceName.PROCESSING_ASSETS_TABLE_NAME.value | ||
region = "ap-southeast-2" # TODO: don't hardcode region | ||
|
||
class ProcessingAssetsModelBase(Model): | ||
pk = UnicodeAttribute(hash_key=True) | ||
sk = UnicodeAttribute(range_key=True) | ||
url = UnicodeAttribute() | ||
multihash = UnicodeAttribute(null=True) | ||
|
||
|
||
def processing_assets_model_with_meta() -> Type[ProcessingAssetsModelBase]: | ||
class ProcessingAssetsModel(ProcessingAssetsModelBase): | ||
class Meta: # pylint:disable=too-few-public-methods | ||
table_name = get_param(ParameterName.PROCESSING_ASSETS_TABLE_NAME) | ||
region = environ["AWS_DEFAULT_REGION"] | ||
|
||
return ProcessingAssetsModel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from typing import Iterable | ||
|
||
import constructs | ||
from aws_cdk import aws_ssm | ||
from aws_cdk.aws_iam import IGrantable | ||
|
||
|
||
class Parameter(aws_ssm.StringParameter): | ||
def __init__( | ||
self, | ||
scope: constructs.Construct, | ||
construct_id: str, | ||
*, | ||
string_value: str, | ||
description: str, | ||
parameter_name: str, | ||
readers: Iterable[IGrantable], | ||
) -> None: | ||
super().__init__( | ||
scope, | ||
construct_id, | ||
string_value=string_value, | ||
description=description, | ||
parameter_name=parameter_name, | ||
) | ||
|
||
for reader in readers: | ||
self.grant_read(reader) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.