Using CodeCommit>CodePipeLine>CodeBuild to deploy Lambda from a Dev account into a seperate Prod account

Hey there

I’m trying to set up a deployment pipeline for our Lambda functions with the following constraint: We want to have all of our Code Commit repos in one account, and I then want to be able to deploy to any of our 8 other AWS Accounts from that account when a commit occurs via Cloudformation updates driven by CodePipeline. I’ve read a few articles with varying levels of convolution involved (some have pipelines on both ends, some have Lambda functions syncing artifacts between buckets in different accounts, some have the buildspec.yml in CodeBuild include instructions to build the Cloudformation stack in the target account) and I really can’t decide what the best option is/ if there’s a better one.

It surprises me that CodePipeline seems to very poorly support deploying between accounts, given that having separate Dev/Prod accounts is seen as best practice. I also suspect given my reading of the forum that I’m gonna spend this week coming up with some convoluted solution only to have them fix it in the next month or so, anyway…

Has anyone got a similar setup working? How did you go about doing so? Any advice would be greatly appreciated.


Related discussions:

CodeBuild with cross-account roles is the way to go.

I’d love to better understand this flow as well - and how that works in real life…

You can use AWS Serverless Application Model (AWS SAM) and run “aws cloudformation package” from CodeBuild and feed the generated template as input artifact to a CHANGE_SET_REPLACE/CHANGE_SET_EXECUTE Cloudformation deploy action.

NB^1: I’m afraid you have to use CLI or Cloudformation to configure your deploy action to use a Cross-Account role and this isn’t very well documented.

NB^2: When using “aws cloudformation package” you need to give an output S3 bucket to store related files, those files will need to be accessible from the AWS account you will be creating your stack from.

Somehow hadn’t come across AWS SAM in my travels, looks promising. I’ll let you know how I go.