-
Notifications
You must be signed in to change notification settings - Fork 90
fix: make arns of all task resources aws-partition aware #131
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
Changes from 2 commits
7a38877
723214e
bee2953
0c9b0f0
162f9db
ae85706
33d624b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
|
||
from stepfunctions.steps.states import Task | ||
from stepfunctions.steps.fields import Field | ||
from stepfunctions.steps.utils import get_aws_partition | ||
|
||
|
||
class LambdaStep(Task): | ||
|
@@ -38,9 +39,9 @@ def __init__(self, state_id, wait_for_callback=False, **kwargs): | |
output_path (str, optional): Path applied to the state’s output after the application of `result_path`, producing the effective output which serves as the raw input for the next state. (default: '$') | ||
""" | ||
if wait_for_callback: | ||
kwargs[Field.Resource.value] = 'arn:aws:states:::lambda:invoke.waitForTaskToken' | ||
kwargs[Field.Resource.value] = 'arn:' + get_aws_partition() + ':states:::lambda:invoke.waitForTaskToken' | ||
else: | ||
kwargs[Field.Resource.value] = 'arn:aws:states:::lambda:invoke' | ||
kwargs[Field.Resource.value] = 'arn:' + get_aws_partition() + ':states:::lambda:invoke' | ||
|
||
super(LambdaStep, self).__init__(state_id, **kwargs) | ||
|
||
|
@@ -67,9 +68,9 @@ def __init__(self, state_id, wait_for_completion=True, **kwargs): | |
output_path (str, optional): Path applied to the state’s output after the application of `result_path`, producing the effective output which serves as the raw input for the next state. (default: '$') | ||
""" | ||
if wait_for_completion: | ||
kwargs[Field.Resource.value] = 'arn:aws:states:::glue:startJobRun.sync' | ||
kwargs[Field.Resource.value] = 'arn:' + get_aws_partition() + ':states:::glue:startJobRun.sync' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would be nice if we extracted the logic for generating ARNs into a utility. additionally, consider string interpolation using you can read more about it here |
||
else: | ||
kwargs[Field.Resource.value] = 'arn:aws:states:::glue:startJobRun' | ||
kwargs[Field.Resource.value] = 'arn:' + get_aws_partition() + ':states:::glue:startJobRun' | ||
|
||
super(GlueStartJobRunStep, self).__init__(state_id, **kwargs) | ||
|
||
|
@@ -96,9 +97,9 @@ def __init__(self, state_id, wait_for_completion=True, **kwargs): | |
output_path (str, optional): Path applied to the state’s output after the application of `result_path`, producing the effective output which serves as the raw input for the next state. (default: '$') | ||
""" | ||
if wait_for_completion: | ||
kwargs[Field.Resource.value] = 'arn:aws:states:::batch:submitJob.sync' | ||
kwargs[Field.Resource.value] = 'arn:' + get_aws_partition() + ':states:::batch:submitJob.sync' | ||
else: | ||
kwargs[Field.Resource.value] = 'arn:aws:states:::batch:submitJob' | ||
kwargs[Field.Resource.value] = 'arn:' + get_aws_partition() + ':states:::batch:submitJob' | ||
|
||
super(BatchSubmitJobStep, self).__init__(state_id, **kwargs) | ||
|
||
|
@@ -125,8 +126,8 @@ def __init__(self, state_id, wait_for_completion=True, **kwargs): | |
output_path (str, optional): Path applied to the state’s output after the application of `result_path`, producing the effective output which serves as the raw input for the next state. (default: '$') | ||
""" | ||
if wait_for_completion: | ||
kwargs[Field.Resource.value] = 'arn:aws:states:::ecs:runTask.sync' | ||
kwargs[Field.Resource.value] = 'arn:' + get_aws_partition() + ':states:::ecs:runTask.sync' | ||
else: | ||
kwargs[Field.Resource.value] = 'arn:aws:states:::ecs:runTask' | ||
kwargs[Field.Resource.value] = 'arn:' + get_aws_partition() + ':states:::ecs:runTask' | ||
|
||
super(EcsRunTaskStep, self).__init__(state_id, **kwargs) |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -12,6 +12,32 @@ | |||||||||||||||
# permissions and limitations under the License. | ||||||||||||||||
from __future__ import absolute_import | ||||||||||||||||
|
||||||||||||||||
import boto3 | ||||||||||||||||
import logging | ||||||||||||||||
|
||||||||||||||||
logger = logging.getLogger('stepfunctions') | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
def tags_dict_to_kv_list(tags_dict): | ||||||||||||||||
kv_list = [{"Key": k, "Value": v} for k,v in tags_dict.items()] | ||||||||||||||||
return kv_list | ||||||||||||||||
kv_list = [{"Key": k, "Value": v} for k, v in tags_dict.items()] | ||||||||||||||||
return kv_list | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
# Obtain matching aws partition name based on region | ||||||||||||||||
# Retrun "aws" as default if no region detected | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo in "Retrun". May be worth mentioning this is from the default boto3 session.
Suggested change
Python method comments are also usually inside the method blocks as a docstring. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure thing. Will make the fix in new commit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oups! Typo here: "Return" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch! I will make the change in next commit |
||||||||||||||||
def get_aws_partition(): | ||||||||||||||||
partitions = boto3.session.Session().get_available_partitions() | ||||||||||||||||
cur_region = boto3.session.Session().region_name | ||||||||||||||||
cur_partition = "aws" | ||||||||||||||||
|
||||||||||||||||
if cur_region is None: | ||||||||||||||||
logger.warning("No region detected for the session, will use default partition: aws") | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I think it's worth mentioning this is for a boto3 session
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. Will do |
||||||||||||||||
return cur_partition | ||||||||||||||||
|
||||||||||||||||
for partition in partitions: | ||||||||||||||||
wong-a marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
regions = boto3.session.Session().get_available_regions("stepfunctions", partition) | ||||||||||||||||
if cur_region in regions: | ||||||||||||||||
cur_partition = partition | ||||||||||||||||
return cur_partition | ||||||||||||||||
|
||||||||||||||||
return cur_partition |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily blocking: I would like to at least consider class for ARN construction instead of building strings with repeated calls to
get_aws_partition()
inline everywhere. The AWS SDK in other languages have utilities for this, but python doesn't.Something like:
Or even scoping it to service integration ARNs:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will definitely make the code cleaner. I will look into it.
If I can not finish this quickly I will prepare a PR specific for it later.