- Newest
- Most votes
- Most comments
Hi,
To diagnose and fix your issue, you may want to follow this KC article: https://repost.aws/knowledge-center/codepipeline-running-twice
You may also find this article interesting: https://medium.com/@shweta2202/step-functions-preventing-duplicate-executions-a4f5f2868381
Best,
Didier
Hello,
Follow these steps to resolve issue:
CodePipeline Configuration:
- Parallel Execution: Ensure that your CodePipeline stage is not configured to run actions in parallel. If it is, this could be causing the two state machines to be triggered simultaneously.
- Dependency Configuration: Verify that the actions within the stage are properly configured to depend on each other. If the state machines are not dependent on each other, they could be executed independently.
State Machine Logic:
- Concurrency Control: Check if the state machine logic includes any mechanisms to prevent concurrent CreateImage operations. If not, you may need to implement a wait state or a conditional branch to ensure that the operation is not attempted while another is in progress.
- Error Handling: Ensure that the state machine is properly handling errors and retrying failed operations if necessary. This can help prevent the state machine from failing prematurely.
SNS and Lambda Configuration:
- Message Deduplication: Verify that the SNS topic is configured to use message deduplication. This can help prevent the Lambda function from being triggered multiple times with the same message.
- Lambda Function Logic: Ensure that the Lambda function is properly handling the SNS message and triggering the state machine only once. Avoid unnecessary retries or parallel executions within the Lambda function.
Related document links:
- CodePipeline Documentation: https://docs.aws.amazon.com/codepipeline/
- AWS Step Functions Documentation: https://docs.aws.amazon.com/step-functions/
- SNS Documentation: https://aws.amazon.com/sns/
- Lambda Documentation: https://console.aws.amazon.com/lambda/home
I included the picture of my step functions state machine for reference
answered 2 years ago
Your Step Function is likely being triggered twice due to a configuration issue in CodePipeline or the state machine itself.
Check:
-
CodePipeline stage: Ensure it's not set to run actions in parallel.
-
State machine: Verify there's no concurrency control issue or missing error handling.
-
SNS and Lambda: Confirm message deduplication and proper Lambda logic.
-
I think the issue is in codePipeLine stage config. I do simple test, by adding stage after deploy with a lambda function. After deploy stage, it run into the stage, and in cloudwatch logs, I do see lambda run twice. If I config notify using sns and lambda then lambda run only once
Relevant content
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 2 years ago

My pipeline execution mode is superseded so I can 100% sure that my pipeline does not run parallel. In state machine at createImage stage, I do not implement mechanisms to prevent concurrent CreateImage operations because I think state machine will run once, but not twice. But if I setup notify in CodePipeline, sns will trigger lambda to start state machine. In that case, state machine only run once. For more information, I manually release change in codePipeline to test the behaviour
Analyze the logs: Examine the logs for CodePipeline, state machine, SNS, and Lambda to identify any errors, warnings, or unexpected behavior.
I examine the log and do see step functions run twice, I also see the fail error, but cannot find any clue to identify why step functions run twice. If codePipeline runs parallel then it would be the case, but the only person trigger codePipeline is me, so there is no parallel execution there. Again, this only happen if I add step functions as stage behind deploy stage. But if I config sns to trigger lambda to run step functions, then state machine is only run once. I don't know why but I will stick with the latter solution until find out the reason