-
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 all 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 |
---|---|---|
|
@@ -12,8 +12,31 @@ | |
# permissions and limitations under the License. | ||
from __future__ import absolute_import | ||
|
||
from enum import Enum | ||
from stepfunctions.steps.states import Task | ||
from stepfunctions.steps.fields import Field | ||
from stepfunctions.steps.integration_resources import IntegrationPattern, get_service_integration_arn | ||
|
||
LAMBDA_SERVICE_NAME = "lambda" | ||
GLUE_SERVICE_NAME = "glue" | ||
ECS_SERVICE_NAME = "ecs" | ||
BATCH_SERVICE_NAME = "batch" | ||
|
||
|
||
class LambdaApi(Enum): | ||
Invoke = "invoke" | ||
|
||
|
||
class GlueApi(Enum): | ||
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. not blocking: also agree that these don't need to be classes. If you do keep them as classes, we should include docstrings that explain what they are and their purpose :) |
||
StartJobRun = "startJobRun" | ||
|
||
|
||
class EcsApi(Enum): | ||
RunTask = "runTask" | ||
|
||
|
||
class BatchApi(Enum): | ||
SubmitJob = "submitJob" | ||
|
||
|
||
class LambdaStep(Task): | ||
|
@@ -37,10 +60,22 @@ def __init__(self, state_id, wait_for_callback=False, **kwargs): | |
result_path (str, optional): Path specifying the raw input’s combination with or replacement by the state’s result. (default: '$') | ||
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' | ||
""" | ||
Example resource arn: arn:aws:states:::lambda:invoke.waitForTaskToken | ||
""" | ||
|
||
kwargs[Field.Resource.value] = get_service_integration_arn(LAMBDA_SERVICE_NAME, | ||
LambdaApi.Invoke, | ||
IntegrationPattern.WaitForTaskToken) | ||
else: | ||
kwargs[Field.Resource.value] = 'arn:aws:states:::lambda:invoke' | ||
""" | ||
Example resource arn: arn:aws:states:::lambda:invoke | ||
""" | ||
|
||
kwargs[Field.Resource.value] = get_service_integration_arn(LAMBDA_SERVICE_NAME, LambdaApi.Invoke) | ||
|
||
|
||
super(LambdaStep, self).__init__(state_id, **kwargs) | ||
|
||
|
@@ -67,9 +102,20 @@ 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' | ||
""" | ||
Example resource arn: arn:aws:states:::glue:startJobRun.sync | ||
""" | ||
|
||
kwargs[Field.Resource.value] = get_service_integration_arn(GLUE_SERVICE_NAME, | ||
GlueApi.StartJobRun, | ||
IntegrationPattern.WaitForCompletion) | ||
else: | ||
kwargs[Field.Resource.value] = 'arn:aws:states:::glue:startJobRun' | ||
""" | ||
Example resource arn: arn:aws:states:::glue:startJobRun | ||
""" | ||
|
||
kwargs[Field.Resource.value] = get_service_integration_arn(GLUE_SERVICE_NAME, | ||
GlueApi.StartJobRun) | ||
|
||
super(GlueStartJobRunStep, self).__init__(state_id, **kwargs) | ||
|
||
|
@@ -96,9 +142,20 @@ 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' | ||
""" | ||
Example resource arn: arn:aws:states:::batch:submitJob.sync | ||
""" | ||
|
||
kwargs[Field.Resource.value] = get_service_integration_arn(BATCH_SERVICE_NAME, | ||
BatchApi.SubmitJob, | ||
IntegrationPattern.WaitForCompletion) | ||
else: | ||
kwargs[Field.Resource.value] = 'arn:aws:states:::batch:submitJob' | ||
""" | ||
Example resource arn: arn:aws:states:::batch:submitJob | ||
""" | ||
|
||
kwargs[Field.Resource.value] = get_service_integration_arn(BATCH_SERVICE_NAME, | ||
BatchApi.SubmitJob) | ||
|
||
super(BatchSubmitJobStep, self).__init__(state_id, **kwargs) | ||
|
||
|
@@ -125,8 +182,19 @@ 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' | ||
""" | ||
Example resource arn: arn:aws:states:::ecs:runTask.sync | ||
""" | ||
|
||
kwargs[Field.Resource.value] = get_service_integration_arn(ECS_SERVICE_NAME, | ||
EcsApi.RunTask, | ||
IntegrationPattern.WaitForCompletion) | ||
else: | ||
kwargs[Field.Resource.value] = 'arn:aws:states:::ecs:runTask' | ||
""" | ||
Example resource arn: arn:aws:states:::ecs:runTask | ||
""" | ||
|
||
kwargs[Field.Resource.value] = get_service_integration_arn(ECS_SERVICE_NAME, | ||
EcsApi.RunTask) | ||
|
||
super(EcsRunTaskStep, self).__init__(state_id, **kwargs) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). | ||
# You may not use this file except in compliance with the License. | ||
# A copy of the License is located at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# or in the "license" file accompanying this file. This file is distributed | ||
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
# express or implied. See the License for the specific language governing | ||
# permissions and limitations under the License. | ||
|
||
from __future__ import absolute_import | ||
|
||
from enum import Enum | ||
from stepfunctions.steps.utils import get_aws_partition | ||
|
||
|
||
class IntegrationPattern(Enum): | ||
""" | ||
Integration pattern enum classes for task integration resource arn builder | ||
""" | ||
|
||
WaitForTaskToken = "waitForTaskToken" | ||
WaitForCompletion = "sync" | ||
wong-a marked this conversation as resolved.
Show resolved
Hide resolved
|
||
RequestResponse = "" | ||
|
||
|
||
def get_service_integration_arn(service, api, integration_pattern=IntegrationPattern.RequestResponse): | ||
|
||
""" | ||
ARN builder for task integration | ||
Args: | ||
service (str): The service name for the service integration | ||
api (str): The api of the service integration | ||
integration_pattern (IntegrationPattern, optional): The integration pattern for the task. (Default: IntegrationPattern.RequestResponse) | ||
""" | ||
arn = "" | ||
if integration_pattern == IntegrationPattern.RequestResponse: | ||
arn = f"arn:{get_aws_partition()}:states:::{service}:{api.value}" | ||
else: | ||
arn = f"arn:{get_aws_partition()}:states:::{service}:{api.value}.{integration_pattern.value}" | ||
return arn | ||
Comment on lines
+40
to
+44
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. really nice to see us leveraging f-strings! |
||
|
||
|
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.
nit (not blocking): Not necessary to be a class