From c701abd5b9ff5e0ebdd62b16e52826e962a2b8c8 Mon Sep 17 00:00:00 2001 From: Tony Sherman Date: Wed, 27 Dec 2023 16:30:19 -0500 Subject: [PATCH 1/8] add ability to customize the prefix of the statemachine name --- README-SAR.md | 1 + template.yml | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/README-SAR.md b/README-SAR.md index a7850d8e..f7247673 100644 --- a/README-SAR.md +++ b/README-SAR.md @@ -72,6 +72,7 @@ The CloudFormation template accepts the following parameters: * **logGroupRetentionInDays** (number, default=7): the number of days to retain log events in the Lambda log groups. Before this parameter existed, log events were retained indefinitely * **securityGroupIds** (list of SecurityGroup IDs): List of Security Groups to use in every Lambda function's VPC Configuration (optional); please note that your VPC should be configured to allow public internet access (via NAT Gateway) or include VPC Endpoints to the Lambda service * **subnetIds** (list of Subnet IDs): List of Subnets to use in every Lambda function's VPC Configuration (optional); please note that your VPC should be configured to allow public internet access (via NAT Gateway) or include VPC Endpoints to the Lambda service +* **stateMachineNamePrefix** (string, default=`powerTuningStateMachine`) Allows you to customize the name of the statemachine. The last portion of the `AWS::StackId` will be appended to this value: `powerTuningStateMachine-89549da0-a4f9-11ee-844d-12a2895ed91f` (The `StateMachineName` has a maximum of 80 characters and 36 from the `StackId` are appended, allowing 44 for a custom prefix.) Please note that the total execution time should stay below 300 seconds (5 min), which is the default timeout. You can easily estimate the total execution timeout based on the average duration of your functions. For example, if your function's average execution time is 5 seconds and you haven't enabled `parallelInvocation`, you should set `totalExecutionTimeout` to at least `num * 5`: 50 seconds if `num=10`, 500 seconds if `num=100`, and so on. If you have enabled `parallelInvocation`, usually you don't need to tune the value of `totalExecutionTimeout` unless your average execution time is above 5 min. diff --git a/template.yml b/template.yml index aa6a3393..d757156d 100644 --- a/template.yml +++ b/template.yml @@ -62,6 +62,10 @@ Parameters: Type: CommaDelimitedList Default: '' Description: List of Subnets to use in every Lambda function's VPC Configuration (optional). + stateMachineNamePrefix: + Type: String + Default: "powerTuningStateMachine" + Description: Prefix to the name of the StateMachine. The StackId will be appended to this value (optional). Conditions: UsePermissionsBoundary: !Not [!Equals [!Ref permissionsBoundary, '']] @@ -262,6 +266,11 @@ Resources: powerTuningStateMachine: Type: AWS::StepFunctions::StateMachine Properties: + StateMachineName: + Fn::Join: + - '-' + - - !Ref stateMachineNamePrefix + - !Select [2, !Split ['/', !Ref AWS::StackId]] RoleArn: !GetAtt statemachineRole.Arn DefinitionString: !Sub From af97380e2b572ac6b1bb97054b2c0725fcbeda80 Mon Sep 17 00:00:00 2001 From: Alex Casalboni Date: Tue, 9 Jan 2024 16:15:56 +0100 Subject: [PATCH 2/8] Add MaxLength for new stateMachineNamePrefix parameter --- template.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/template.yml b/template.yml index d757156d..ae0fc451 100644 --- a/template.yml +++ b/template.yml @@ -64,6 +64,7 @@ Parameters: Description: List of Subnets to use in every Lambda function's VPC Configuration (optional). stateMachineNamePrefix: Type: String + MaxLength: 44 Default: "powerTuningStateMachine" Description: Prefix to the name of the StateMachine. The StackId will be appended to this value (optional). From 91b7dd58fdbc123b68e9c0facd79047720e00699 Mon Sep 17 00:00:00 2001 From: Tony Sherman Date: Tue, 9 Jan 2024 10:42:06 -0500 Subject: [PATCH 3/8] add AllowedPattern limit to stateMachineNamePrefix parameter --- template.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/template.yml b/template.yml index ae0fc451..bf393f56 100644 --- a/template.yml +++ b/template.yml @@ -65,7 +65,9 @@ Parameters: stateMachineNamePrefix: Type: String MaxLength: 44 - Default: "powerTuningStateMachine" + AllowedPattern: ^[a-zA-Z0-9]*$ + ConstraintDescription: Prefix must conform to StateMachineName requirements. + Default: 'powerTuningStateMachine' Description: Prefix to the name of the StateMachine. The StackId will be appended to this value (optional). Conditions: From 685e4a7c3e55686a420ccc9a7c153687e95fabfc Mon Sep 17 00:00:00 2001 From: Alex Casalboni Date: Mon, 15 Jan 2024 14:13:01 +0100 Subject: [PATCH 4/8] add more characters to stateMachineNamePrefix regex --- template.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template.yml b/template.yml index bf393f56..618d49ea 100644 --- a/template.yml +++ b/template.yml @@ -65,7 +65,7 @@ Parameters: stateMachineNamePrefix: Type: String MaxLength: 44 - AllowedPattern: ^[a-zA-Z0-9]*$ + AllowedPattern: ^[a-zA-Z0-9\-_]*$ ConstraintDescription: Prefix must conform to StateMachineName requirements. Default: 'powerTuningStateMachine' Description: Prefix to the name of the StateMachine. The StackId will be appended to this value (optional). From ba2ff9fd51b7e851c9d3d44afbf7cfc2ccab05f8 Mon Sep 17 00:00:00 2001 From: Alex Casalboni Date: Mon, 15 Jan 2024 14:24:09 +0100 Subject: [PATCH 5/8] Update SAR script with new stateMachineNamePrefix parameter --- scripts/deploy-sar-app.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/deploy-sar-app.yml b/scripts/deploy-sar-app.yml index 96affcef..e1f756dd 100644 --- a/scripts/deploy-sar-app.yml +++ b/scripts/deploy-sar-app.yml @@ -18,6 +18,7 @@ Resources: # permissionsBoundary: ARN # payloadS3Bucket: my-bucket # payloadS3Key: my-key.json + # stateMachineNamePrefix: my-custom-name-prefix Outputs: PowerTuningStateMachine: From a92409612f9170a1b5b268bbe401eab380eb16c3 Mon Sep 17 00:00:00 2001 From: Alex Casalboni Date: Mon, 15 Jan 2024 14:24:25 +0100 Subject: [PATCH 6/8] Update all docs for the new stateMachineNamePrefix parameter --- README-INPUT-OUTPUT.md | 1 + README-SAR.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README-INPUT-OUTPUT.md b/README-INPUT-OUTPUT.md index ab2e82d6..f6866829 100644 --- a/README-INPUT-OUTPUT.md +++ b/README-INPUT-OUTPUT.md @@ -39,6 +39,7 @@ The CloudFormation template accepts the following parameters: * **logGroupRetentionInDays** (number, default=7): the number of days to retain log events in the Lambda log groups. Before this parameter existed, log events were retained indefinitely * **securityGroupIds** (list of SecurityGroup IDs): List of Security Groups to use in every Lambda function's VPC Configuration (optional); please note that your VPC should be configured to allow public internet access (via NAT Gateway) or include VPC Endpoints to the Lambda service * **subnetIds** (list of Subnet IDs): List of Subnets to use in every Lambda function's VPC Configuration (optional); please note that your VPC should be configured to allow public internet access (via NAT Gateway) or include VPC Endpoints to the Lambda service +* **stateMachineNamePrefix** (string, default=`powerTuningStateMachine`): Allows you to customize the name of the state machine. The last portion of the `AWS::StackId` will be appended to this value, so the state machine name will look like `powerTuningStateMachine-89549da0-a4f9-11ee-844d-12a2895ed91f`. The `StateMachineName` has a maximum of 80 characters and 36 from the `StackId` are appended, allowing 44 for a custom prefix (only alphanumeric characters, plus `-` and `_`). Please note that the total execution time should stay below 300 seconds (5 min), which is the default timeout. You can easily estimate the total execution timeout based on the average duration of your functions. For example, if your function's average execution time is 5 seconds and you haven't enabled `parallelInvocation`, you should set `totalExecutionTimeout` to at least `num * 5`: 50 seconds if `num=10`, 500 seconds if `num=100`, and so on. If you have enabled `parallelInvocation`, usually you don't need to tune the value of `totalExecutionTimeout` unless your average execution time is above 5 min. If you have a sleep between invocations set, you should include that in your timeout calculations. diff --git a/README-SAR.md b/README-SAR.md index f7247673..646dfeaa 100644 --- a/README-SAR.md +++ b/README-SAR.md @@ -72,7 +72,7 @@ The CloudFormation template accepts the following parameters: * **logGroupRetentionInDays** (number, default=7): the number of days to retain log events in the Lambda log groups. Before this parameter existed, log events were retained indefinitely * **securityGroupIds** (list of SecurityGroup IDs): List of Security Groups to use in every Lambda function's VPC Configuration (optional); please note that your VPC should be configured to allow public internet access (via NAT Gateway) or include VPC Endpoints to the Lambda service * **subnetIds** (list of Subnet IDs): List of Subnets to use in every Lambda function's VPC Configuration (optional); please note that your VPC should be configured to allow public internet access (via NAT Gateway) or include VPC Endpoints to the Lambda service -* **stateMachineNamePrefix** (string, default=`powerTuningStateMachine`) Allows you to customize the name of the statemachine. The last portion of the `AWS::StackId` will be appended to this value: `powerTuningStateMachine-89549da0-a4f9-11ee-844d-12a2895ed91f` (The `StateMachineName` has a maximum of 80 characters and 36 from the `StackId` are appended, allowing 44 for a custom prefix.) +* **stateMachineNamePrefix** (string, default=`powerTuningStateMachine`): Allows you to customize the name of the state machine. The last portion of the `AWS::StackId` will be appended to this value, so the state machine name will look like `powerTuningStateMachine-89549da0-a4f9-11ee-844d-12a2895ed91f`. The `StateMachineName` has a maximum of 80 characters and 36 from the `StackId` are appended, allowing 44 for a custom prefix (only alphanumeric characters, plus `-` and `_`). Please note that the total execution time should stay below 300 seconds (5 min), which is the default timeout. You can easily estimate the total execution timeout based on the average duration of your functions. For example, if your function's average execution time is 5 seconds and you haven't enabled `parallelInvocation`, you should set `totalExecutionTimeout` to at least `num * 5`: 50 seconds if `num=10`, 500 seconds if `num=100`, and so on. If you have enabled `parallelInvocation`, usually you don't need to tune the value of `totalExecutionTimeout` unless your average execution time is above 5 min. From 2c409ce3753a02fc358836948232c11ddd839d7c Mon Sep 17 00:00:00 2001 From: Alex Casalboni Date: Mon, 15 Jan 2024 14:25:20 +0100 Subject: [PATCH 7/8] Terraform: use name_prefix instead of name for the state machine --- terraform/module/state_machine.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/module/state_machine.tf b/terraform/module/state_machine.tf index 3550ea8d..07097638 100644 --- a/terraform/module/state_machine.tf +++ b/terraform/module/state_machine.tf @@ -1,6 +1,6 @@ resource "aws_sfn_state_machine" "state-machine" { - name = var.lambda_function_prefix + name_prefix = var.lambda_function_prefix role_arn = aws_iam_role.sfn_role.arn definition = local.state_machine From 5ecb337cf30f93a1927e4aa5b7b5933f7dfae44b Mon Sep 17 00:00:00 2001 From: Alex Casalboni Date: Mon, 15 Jan 2024 14:36:14 +0100 Subject: [PATCH 8/8] Only allow 43 characters for stateMachineNamePrefix, updated doc too --- README-INPUT-OUTPUT.md | 2 +- README-SAR.md | 2 +- template.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README-INPUT-OUTPUT.md b/README-INPUT-OUTPUT.md index f6866829..e11c1dcc 100644 --- a/README-INPUT-OUTPUT.md +++ b/README-INPUT-OUTPUT.md @@ -39,7 +39,7 @@ The CloudFormation template accepts the following parameters: * **logGroupRetentionInDays** (number, default=7): the number of days to retain log events in the Lambda log groups. Before this parameter existed, log events were retained indefinitely * **securityGroupIds** (list of SecurityGroup IDs): List of Security Groups to use in every Lambda function's VPC Configuration (optional); please note that your VPC should be configured to allow public internet access (via NAT Gateway) or include VPC Endpoints to the Lambda service * **subnetIds** (list of Subnet IDs): List of Subnets to use in every Lambda function's VPC Configuration (optional); please note that your VPC should be configured to allow public internet access (via NAT Gateway) or include VPC Endpoints to the Lambda service -* **stateMachineNamePrefix** (string, default=`powerTuningStateMachine`): Allows you to customize the name of the state machine. The last portion of the `AWS::StackId` will be appended to this value, so the state machine name will look like `powerTuningStateMachine-89549da0-a4f9-11ee-844d-12a2895ed91f`. The `StateMachineName` has a maximum of 80 characters and 36 from the `StackId` are appended, allowing 44 for a custom prefix (only alphanumeric characters, plus `-` and `_`). +* **stateMachineNamePrefix** (string, default=`powerTuningStateMachine`): Allows you to customize the name of the state machine. Maximum 43 characters, only alphanumeric (plus `-` and `_`). The last portion of the `AWS::StackId` will be appended to this value, so the full name will look like `powerTuningStateMachine-89549da0-a4f9-11ee-844d-12a2895ed91f`. Note: `StateMachineName` has a maximum of 80 characters and 36+1 from the `StackId` are appended, allowing 43 for a custom prefix. Please note that the total execution time should stay below 300 seconds (5 min), which is the default timeout. You can easily estimate the total execution timeout based on the average duration of your functions. For example, if your function's average execution time is 5 seconds and you haven't enabled `parallelInvocation`, you should set `totalExecutionTimeout` to at least `num * 5`: 50 seconds if `num=10`, 500 seconds if `num=100`, and so on. If you have enabled `parallelInvocation`, usually you don't need to tune the value of `totalExecutionTimeout` unless your average execution time is above 5 min. If you have a sleep between invocations set, you should include that in your timeout calculations. diff --git a/README-SAR.md b/README-SAR.md index 646dfeaa..5c274d34 100644 --- a/README-SAR.md +++ b/README-SAR.md @@ -72,7 +72,7 @@ The CloudFormation template accepts the following parameters: * **logGroupRetentionInDays** (number, default=7): the number of days to retain log events in the Lambda log groups. Before this parameter existed, log events were retained indefinitely * **securityGroupIds** (list of SecurityGroup IDs): List of Security Groups to use in every Lambda function's VPC Configuration (optional); please note that your VPC should be configured to allow public internet access (via NAT Gateway) or include VPC Endpoints to the Lambda service * **subnetIds** (list of Subnet IDs): List of Subnets to use in every Lambda function's VPC Configuration (optional); please note that your VPC should be configured to allow public internet access (via NAT Gateway) or include VPC Endpoints to the Lambda service -* **stateMachineNamePrefix** (string, default=`powerTuningStateMachine`): Allows you to customize the name of the state machine. The last portion of the `AWS::StackId` will be appended to this value, so the state machine name will look like `powerTuningStateMachine-89549da0-a4f9-11ee-844d-12a2895ed91f`. The `StateMachineName` has a maximum of 80 characters and 36 from the `StackId` are appended, allowing 44 for a custom prefix (only alphanumeric characters, plus `-` and `_`). +* **stateMachineNamePrefix** (string, default=`powerTuningStateMachine`): Allows you to customize the name of the state machine. Maximum 43 characters, only alphanumeric (plus `-` and `_`). The last portion of the `AWS::StackId` will be appended to this value, so the full name will look like `powerTuningStateMachine-89549da0-a4f9-11ee-844d-12a2895ed91f`. Note: `StateMachineName` has a maximum of 80 characters and 36+1 from the `StackId` are appended, allowing 43 for a custom prefix. Please note that the total execution time should stay below 300 seconds (5 min), which is the default timeout. You can easily estimate the total execution timeout based on the average duration of your functions. For example, if your function's average execution time is 5 seconds and you haven't enabled `parallelInvocation`, you should set `totalExecutionTimeout` to at least `num * 5`: 50 seconds if `num=10`, 500 seconds if `num=100`, and so on. If you have enabled `parallelInvocation`, usually you don't need to tune the value of `totalExecutionTimeout` unless your average execution time is above 5 min. diff --git a/template.yml b/template.yml index 618d49ea..0b9d4518 100644 --- a/template.yml +++ b/template.yml @@ -64,7 +64,7 @@ Parameters: Description: List of Subnets to use in every Lambda function's VPC Configuration (optional). stateMachineNamePrefix: Type: String - MaxLength: 44 + MaxLength: 43 AllowedPattern: ^[a-zA-Z0-9\-_]*$ ConstraintDescription: Prefix must conform to StateMachineName requirements. Default: 'powerTuningStateMachine'