Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add aws_region #38

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
14 changes: 13 additions & 1 deletion snakemake_storage_plugin_s3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ class StorageProviderSettings(StorageProviderSettingsBase):
"required": False,
},
)
aws_region: Optional[str] = field(
default = None,
metadata={
"help": "AWS S3 region constraint for AWS S3 storage requirement"
"env_var": True
"required": False
}
)
access_key: Optional[str] = field(
default=None,
metadata={
Expand Down Expand Up @@ -115,6 +123,7 @@ def __post_init__(self):
self.s3c = boto3.resource(
"s3",
endpoint_url=self.settings.endpoint_url,
aws_region=self.settings.aws_region,
aws_access_key_id=self.settings.access_key,
aws_secret_access_key=self.settings.secret_key,
aws_session_token=self.settings.token,
Expand Down Expand Up @@ -312,7 +321,10 @@ def store_object(self):
# Ensure that the object is stored at the location specified by
# self.local_path().
if not self.bucket_exists():
self.provider.s3c.create_bucket(Bucket=self.bucket)
location_config = None
if self.provider.settings.aws_region is not None:
location_config = {'LocationConstraint': self.provider.settings.region_name}
self.provider.s3c.create_bucket(Bucket=self.bucket, CreateBucketConfiguration=location_config)

if self.local_path().is_dir():
self._is_dir = True
Expand Down
Loading