I have an AWS codpipeline created with CDK and I want to deploy to a codedeploy deployment group in another account. Any Idea how I can import an existing deployment group in another account into my stack?
I have an AWS codpipeline created with CDK and I want to deploy to a codedeploy deployment group in another account. Any Idea how I can import an existing deployment group in another account into my stack?
You can't do that. CloudFormation is account and region based. You can't create a stack which manages resources in other account.
The current accepted answer is not wrong, but also only half the story.
Cloudformation itself cannot manage resources in multiple accounts. This is true.
However, your CodePipeline can assume a role in another account and deploy a Cloduformation Stack to that account. This is a common practice when having a Dev environment and a Prod Environment - you restrict access to changing anything in the prod account to just a single role that CodePipeline can assume and deploy for you - but no users can. (see https://docs.aws.amazon.com/codepipeline/latest/userguide/pipelines-create-cross-account.html for some more info)
So if you have. CDK app for your Stack Group, then you can re-use that to deploy to the other account - this is widely accepted and one of the primary uses cases for CDK - multi account deployment of the same basic constructs.
Any resources that are being used cross account will need to have their own Lambdas or scripts in an EC2 instance that assumes another cross account role that gives them access to that resource to retrieve whatever it is you need.
You cannot however, with a single cloud formation stack (or cdk stack) deploy to both accounts - but you can do so with multiple stacks through a single CodePipeline