Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to deploy a previously aws-cdk synthesized stack?

Tags:

aws-cdk

The aws-cdk allows you to synthesize a stack - which produces a number of files - including a .template.json file.

Can this .template.json file be deployed without the aws-cdk tool? Or is it designed to require deployment via the aws-cdk tool?

The reason I ask, it that I would like to synthesize the template through CI (Continuous Integration), store that to a repository and then use a CD (Continuous Deployment) tool to deploy that template.

I could have the CD tool run the aws-cdk deploy. But I'd rather not do this as there is a change that the generated template may differ from the version stored in the repository by the CI tool. (For example if there is aws-cdk version differences between CI/ CD tools).

Update 13th Dec 2019

The short answer appears to be yes. Yes you can deploy the template generated by aws-cdk

The longer answer appears to be that it becomes complicated if you are using assets in your stack (lambda code for example). These will generate parameters in the template which need to be completed if you deploy the stack outside of aws-cdk.

I'm sure that it possible - but I have to admit, for the short term, I'm just going to use aws-cdk to complete the deployment - it seems to be less complicated.

like image 896
Mark Taylor Avatar asked Dec 12 '19 17:12

Mark Taylor


2 Answers

Ok, after a bit of work I believe I have a solution.

As part of my CI (Continuous Integration) job I run:

cdk synth

I then save the contents of the cdk.out folder to a repository (I'm using Octopus Deployment).

As part of my CD (Continuous Deployment) job I have the following (Powershell):

$Env:AWS_ACCESS_KEY_ID={your key}
$Env:AWS_SECRET_ACCESS_KEY={your secret}
$Env:AWS_DEFAULT_REGION={your region}

$cdk=[Environment]::GetFolderPath([Environment+SpecialFolder]::ApplicationData) + "\npm\cdk.cmd"
& $cdk --app . deploy {your stack name} --require-approval never

So the "cdk synth" will generate the template and assets required for deployment.

The "cdk --app . depoy {your stack name} --require-approval never" is telling aws-cdk to us the existing templates and assets. This avoids a situation where the CD process may produce a different setup than the CI process. The "." indicates that the templates & assets are in the current folder.

You will need to install node & aws-cdk on the CD server (in my case an Octopus Deploy tentacle);

Node install is easy, just log in and install.

To add aws-cdk perform the following (using an administrator powershell):

npm prefix -g  // Make note of the path
npm config set prefix C:\Windows\System32\config\systemprofile\AppData\Roaming\npm
npm install -g aws-cdk
npm config set prefix {original path}

Note that the npm path maybe different for your usage - will depend on the user account used for the CD process and Windows version.

like image 147
Mark Taylor Avatar answered Sep 28 '22 03:09

Mark Taylor


One option is to generate a CloudFormation ChangeSet using CDK and then deploy that ChangeSet later. To create the ChangeSet run cdk deploy <StackName> --execute false. This will synthesize the stack as well as upload templates and assets to S3. The ChangeSet can then be executed at anytime without CDK.

like image 40
Edward Foyle Avatar answered Sep 28 '22 04:09

Edward Foyle