This is a basic question: I have a basic codepipeline pipeline set up like the following:
That all makes sense and is straightforward.
Now I want to do the same thing for staging: have a staging branch, and when it's commited to, Codebuild builds it, and it's deployed to the appname-staging environment.
What's the right way to do this?
Should I just have two different pipelines (one for prod and one for staging)?
Or is there a good way to have both of those behaviors (and potentially a third) within the same pipeline?
You need to have a pipeline per branch from my experience. It may be the case that the pipeline structure for each environment is different or the same.
If you opt to do a CI/CD setup, then the non-production pipeline will include stages for testing etc and assuming each stage passes, the deployment will be then automatic to the non-prod elasticbeanstalk environment.
For the production environment, you may wish to include a manual approval stage thus having a continuous delivery pipeline. Or if it is ok to do automatic deployments you could use the pipeline format for non-prod.
A nice trick if you wish to use a pipeline you've created manually over and over again. Is to extract a cloudformation template of it via the cli.
aws codepipeline getpipeline --name <name>
This gives you a cloudformation template for the codepipeline resource. You will need to edit a bit, but if it references a repo and branch, you can adjust that. You can also parameterise it so that you can create many pipelines easily which have a similar structure.