如何在 StepFunction 名称中使用 CloudFormation 参数

时间:2021-05-31 06:53:21

标签: python python-3.x amazon-web-services aws-step-functions

在 python AWS CDK v1.92.0 中,我可以在 Step Function 名称中使用 CF 参数,但在 v1.93.0 中添加了一条 linting 规则,现在它破坏了我的代码。

https://github.com/aws/aws-cdk/issues/13289
https://github.com/aws/aws-cdk/commit/6c3d4071746179dde30f615602592c2523daa56e
https://github.com/aws/aws-cdk/commit/58de0de5a54b9d8fb4658566e85ef408c8861088

我需要一个解决方案或变通办法,以便我可以继续部署我的代码。

声明输入 cfn 参数


    project_id = core.CfnParameter(
        self, id='Project Id', description='Must be unique within your account. \
        Only lowercase characters, . and - are allowed. Max 12 character length.',
        constraint_description='Must be lowercase char, numbers, . or - with a length of 1-12 char.',
        allowed_pattern='([a-z0-9.-])+', max_length=12) 

创建阶梯函数


    sfn_sandbox_sm, sfn_preprod_sm, sfn_prod_sm = self.create_step_functions(
        suffix='inference', project_id=project_id)
    
    sfn_sandbox_sm = stepfunctions.StateMachine(
        self, f'state-machine-{suffix}-sandbox', definition=start_state_sandbox,
        state_machine_name=f'ml-factory-sf-{suffix}-{project_id.value_as_string}-sandbox'
    )

更新到 v1.93.0 后我收到的错误是:

  • ml-factory-sf-{suffix}-{project_id.value_as_string}-sandbox
  • 状态机名称必须匹配“^[0-9a-zA-Z+!@._-]+$”。已收到: ml-factory-sf-inference-${Token[TOKEN.327]}-sandbox

    Traceback (most recent call last):
      File "app.py", line 61, in <module>
        env=environ)
      File "/usr/local/share/pip-global/jsii/_runtime.py", line 83, in __call__
        inst = super().__call__(*args, **kwargs)
      File "/workspaces/ml-factory-aws/stacks/cdk_pipeline_stack.py", line 95, in __init__
        deployment_id='test', env=preprod_env)
      File "/usr/local/share/pip-global/jsii/_runtime.py", line 83, in __call__
        inst = super().__call__(*args, **kwargs)
      File "/workspaces/ml-factory-aws/stacks/cdk_pipeline_stage_stack.py", line 51, in __init__
        env=account_env)
      File "/usr/local/share/pip-global/jsii/_runtime.py", line 83, in __call__
        inst = super().__call__(*args, **kwargs)
      File "/workspaces/ml-factory-aws/stacks/s3_resource_stack.py", line 42, in __init__
        env=account_env)
      File "/usr/local/share/pip-global/jsii/_runtime.py", line 83, in __call__
        inst = super().__call__(*args, **kwargs)
      File "/workspaces/ml-factory-aws/stacks/ds_sc_product_stack.py", line 77, in __init__
        suffix='inference', project_id=project_id)
      File "/workspaces/ml-factory-aws/stacks/ds_sc_product_stack.py", line 1199, in create_step_functions
        state_machine_name=f'ml-factory-sf-{suffix}-{project_id.value_as_string}-sandbox',
      File "/usr/local/share/pip-global/jsii/_runtime.py", line 83, in __call__
        inst = super().__call__(*args, **kwargs)
      File "/usr/local/share/pip-global/aws_cdk/aws_stepfunctions/__init__.py", line 5100, in __init__
        jsii.create(StateMachine, self, [scope, id, props])
      File "/usr/local/share/pip-global/jsii/_kernel/__init__.py", line 282, in create
        for iface in getattr(klass, "__jsii_ifaces__", [])
      File "/usr/local/share/pip-global/jsii/_kernel/providers/process.py", line 344, in create
        return self._process.send(request, CreateResponse)
      File "/usr/local/share/pip-global/jsii/_kernel/providers/process.py", line 326, in send
        raise JSIIError(resp.error) from JavaScriptError(resp.stack)
    jsii.errors.JSIIError: State Machine name must match "^[0-9a-zA-Z+!@._-]+$". Received: ml-factory-sf-inference-${Token[TOKEN.327]}-sandbox

0 个答案:

没有答案