I don't believe that you can pull this out with a single CodePipeline, at least you can't do it natively.
In general, you either have PollForSourceChanges or webhook enabled or you don't. As you are using Github Version 2 Connection as far I can see from the screenshot, changes in either of the repos will trigger your pipeline as you describe.
I can think of a few options which could solve your issue and from which you can choose based on your use case.
- The obvious one would be to have one pipeline per repo (one for dm and one for sampling - in that case whenever there is a change in one of them you'll just build and deploy to the respective microservice (you'll need to absorb the cost of 1$ for one additional pipeline in that region)
- You can produce a hash of the build on the second step and then add a check prior the deployment to see whether the checksums are matching and if they are do not deploy the new build for this service.
- You can potentially add a check in the buildspec of the build to see whether the commit id from the current execution matches the previous one and if that's the case silently ignore it and don't produce a build. Then have another check in the one with which you deploy the microservice to see whether there is a new build and in case the answer is no, do not deploy.
- You can still use this pipeline for the builds, but then cascade it to another one (or another job for the deployment process). In that job (could be a lambda) you can check whether the commit id from each repo matches the commit version from the previous exectuon and then only deploy to the one that was actually changed.
If it was me, and in case there is some context that we are missing, as you havent mentioned it, the best possible approach is Option 1, just create two separate pipelines, as the other options are adding unneeded complexity.