This repository contains GitHub Actions workflows for managing AWS Step Function executions with enhanced GitHub context tracking. Context introduced includes:
- Repository information (owner/repo)
- Git reference and commit SHA
- Actor (user who triggered the workflow)
- Workflow run details (ID, number, name)
- Job information
- Event details (type, ref, pull request number)
- Short SHA for readable execution names
The Step Function Executor system provides a standardized way to trigger AWS Step Functions with descriptive execution names and comprehensive GitHub context information. This helps developers quickly identify which Step Function execution was triggered by which change.
- Descriptive Execution Names: Execution names include repository, commit SHA, PR number (if applicable), and author
- GitHub Context Integration: Automatically includes GitHub context in Step Function inputs
- Character Limit Management: Handles AWS Step Function execution name length limitations (256 characters)
- Flexible Configuration: Supports both with and without GitHub context
- Reusable Workflow: Can be called from any other workflow
.github/workflows/step-function-executor.yaml
- Reusable workflow for executing Step Functions
.github/workflows/trigger-smoke-test.yaml
- Updated smoke test workflow using the executor.github/workflows/example-step-function-usage.yaml
- Comprehensive examples of different usage patterns
- name: Execute Step Function
uses: ./.github/workflows/step-function-executor.yaml
with:
state_machine_arn: "arn:aws:states:us-east-1:123456789012:stateMachine:MyStateMachine"
execution_name_prefix: "myapp"
input_data: |
{
"environment": "prod",
"data": "example"
}
include_github_context: "true"
Parameter | Required | Description |
---|---|---|
state_machine_arn |
Yes | The ARN of the Step Function state machine |
execution_name_prefix |
Yes | Prefix for the execution name |
input_data |
Yes | JSON string containing input data |
include_github_context |
No | Whether to include GitHub context (default: "true") |
max_execution_name_length |
No | Maximum execution name length (default: "256") |
When include_github_context
is enabled, execution names follow this format:
- For Pull Requests:
{prefix}-{repo}-{short_sha}-pr{number}-{actor}-{uuid}
- For Other Events:
{prefix}-{repo}-{short_sha}-{actor}-{uuid}
Example: smoketest-myapp-a1b2c3d-pr123-john.doe-550e8400
When include_github_context
is enabled, the following context is automatically added to the Step Function input:
{
"your_input_data": "...",
"github_context": {
"repository": "owner/repo",
"ref": "refs/heads/main",
"sha": "a1b2c3d4e5f6...",
"short_sha": "a1b2c3d",
"actor": "john.doe",
"run_id": "1234567890",
"run_number": "42",
"workflow": "My Workflow",
"job": "my-job",
"event_name": "push",
"event_ref": "refs/heads/main",
"event_head_ref": null,
"event_base_ref": null,
"event_pull_request_number": null
}
}
- name: Execute Step Function
uses: ./.github/workflows/step-function-executor.yaml
with:
state_machine_arn: "arn:aws:states:us-east-1:123456789012:stateMachine:BasicStateMachine"
execution_name_prefix: "basic"
input_data: |
{
"environment": "dev",
"message": "Basic execution"
}
include_github_context: "true"
- name: Execute Step Function
uses: ./.github/workflows/step-function-executor.yaml
with:
state_machine_arn: "arn:aws:states:us-east-1:123456789012:stateMachine:CustomStateMachine"
execution_name_prefix: "custom"
input_data: |
{
"custom_field": "example_value",
"timestamp": "2024-01-01T00:00:00Z"
}
include_github_context: "false"
- name: Prepare complex input
id: prepare_input
run: |
COMPLEX_INPUT=$(jq -n \
--arg env "${{ github.event.inputs.environment || 'dev' }}" \
--arg sha "${{ github.sha }}" \
'{
environment: $env,
deployment_info: {
commit_sha: $sha,
timestamp: now | todateiso8601
}
}'
)
echo "complex_input=$COMPLEX_INPUT" >> $GITHUB_OUTPUT
- name: Execute Step Function
uses: ./.github/workflows/step-function-executor.yaml
with:
state_machine_arn: "arn:aws:states:us-east-1:123456789012:stateMachine:ComplexStateMachine"
execution_name_prefix: "complex"
input_data: ${{ steps.prepare_input.outputs.complex_input }}
include_github_context: "true"
The workflow provides the following outputs:
execution_arn
: The ARN of the started Step Function executionexecution_name
: The name of the execution
These can be used in subsequent steps or jobs:
jobs:
my-job:
outputs:
execution_arn: ${{ jobs.execute-step-function.outputs.execution_arn }}
execution_name: ${{ jobs.execute-step-function.outputs.execution_name }}
AWS Step Functions have a 256-character limit for execution names. The workflow automatically:
- Calculates available space (256 - 9 characters for 8-character UUID)
- Truncates the execution name if necessary
- Adds a UUID for uniqueness
- Use Descriptive Prefixes: Choose prefixes that clearly identify the purpose (e.g., "smoketest", "deploy", "validate")
- Include GitHub Context: Enable
include_github_context
for better traceability - Handle Outputs: Capture execution ARNs for downstream processing
- Test Execution Names: Verify your execution names don't exceed limits in your environment
- Use Consistent Naming: Follow a consistent pattern across your workflows
- Execution Name Too Long: The workflow automatically truncates names, but ensure your prefix is reasonable
- Invalid JSON Input: Ensure your
input_data
is valid JSON - Missing Permissions: Ensure the workflow has proper AWS permissions to execute Step Functions
The workflow includes detailed logging and will display:
- The generated execution name
- The input data being sent
- The execution ARN upon successful start
- A summary in the GitHub Actions step summary
To migrate from direct aws stepfunctions start-execution
calls:
- Replace the direct AWS CLI call with the reusable workflow
- Move your input data to the
input_data
parameter - Set an appropriate
execution_name_prefix
- Enable
include_github_context
for better traceability
Example migration:
Before:
- name: Trigger Step Function
run: |
aws stepfunctions start-execution \
--state-machine-arn "$STATE_MACHINE_ARN" \
--input "$INPUT_JSON"
After:
- name: Execute Step Function
uses: ./.github/workflows/step-function-executor.yaml
with:
state_machine_arn: "$STATE_MACHINE_ARN"
execution_name_prefix: "myapp"
input_data: "$INPUT_JSON"
include_github_context: "true"