I am implementing a CICD pipeline using CodePipeline, CodeCommit, CodeDeploy and CloudFormation (I skipped the build part of the pipeline and am going to commit built code for the moment).
I already have a CloudFormation template that creates the required infrastructure to host the application, a CodeDeploy Application (in a nested stack) and a CodePipeline that gets the source code from CodeCommit, does In-Place deployments via CodeDeploy and finally sends an approval email (in a nested stack).
I would like to implement the following:
In order to create the required infrastructure to host the application for the first time, I launch a CloudFormation template that creates (I already have this):
- The required infrastructure to host the application (AutoScalingGroup and Launch Config, TargetGroup and ListenerRules, IAM roles)
- CodeDeploy Application and DeploymentGroup (this will be in a nested stack)
- CodePipeline pipeline pre-configured to carry out the next steps (this will be in a nested stack)
When source code is committed to CodeCommit, CodePipeline launches a new CloudFormation stack containing the required infrastructure to host the application, then deploys the new version of the code to this stack, without affecting the existing stack for the old version of this application. The new stack will have a listener rule with a different host name, so I can test the application while users keep using the old version;
Once the code has been deployed, CodePipeline sends an approval email (through an SNS topic and I already have this);
If the email is approved, the old stack (created in step 1. ) is deleted
I will manually swap the listener rules for the two stacks to direct users to the new stack created in step 2, then delete the old stack.
I am struggling to implement step 2 and currently trying to use a Deploy action with a CloudFormation deployment provider to carry out step 2. above. I am struggling to pass the output artifacts (new source code) from the previous stage to the new stack.
Can you provide some guidelines on how to implement step 2 ?