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

add ability to customize the prefix of the statemachine name #223

Merged
1 change: 1 addition & 0 deletions README-INPUT-OUTPUT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. 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.
Expand Down
1 change: 1 addition & 0 deletions README-SAR.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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.

Expand Down
1 change: 1 addition & 0 deletions scripts/deploy-sar-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Resources:
# permissionsBoundary: ARN
# payloadS3Bucket: my-bucket
# payloadS3Key: my-key.json
# stateMachineNamePrefix: my-custom-name-prefix

Outputs:
PowerTuningStateMachine:
Expand Down
12 changes: 12 additions & 0 deletions template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ Parameters:
Type: CommaDelimitedList
Default: ''
Description: List of Subnets to use in every Lambda function's VPC Configuration (optional).
stateMachineNamePrefix:
Type: String
MaxLength: 43
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:
UsePermissionsBoundary: !Not [!Equals [!Ref permissionsBoundary, '']]
Expand Down Expand Up @@ -262,6 +269,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
Expand Down
2 changes: 1 addition & 1 deletion terraform/module/state_machine.tf
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading