Using CDK (Cloud Development Kit) from AWS language type as TypeScript

This blogpost is about using AWS CDK which is software development approach from AWS to create infrastructure as a code to define and provision resources in AWS. The output of AWS CDK in turns generate AWS cloud Formation template, the benefits in programming in this way is that you have a software defined way to program your resources (Infrastructure resources) in the language of your choice (currently C#/.NET, Java, JavaScript, Python, or TypeScript are supported), debug it locally, iterative develop it, version control it and once your satisfy deploy it.

I had followed below mentioned links from AWS to get started and one caveat is that to use CDK is as stated by AWS

This documentation is for the developer preview release (public beta) of the AWS Cloud Development Kit (AWS CDK). Releases might lack important features and might have future breaking changes.

And I will show how this effect the resources creation in my demonstration below.

https://docs.aws.amazon.com/cdk/latest/guide/home.html

https://github.com/awslabs/aws-cdk

Their are certain prerequisites to get started.

1. Nodejs installed having version greater than 8.11, I have v10.16.0 in my vagrant box.
2. AWS CLI (optional)
3. Setting your AWS_REGION and profile of AWS , if you have multiple AWS accounts.

Installing AWS CDK

Use below command
npm install -g aws-cdk to install latest cdk version, but if you want to limit to a version you can specify a version as npm install -g aws-cdk@0.33 (for example).


Step 1. Setting up the directory structure and initializing app directory with language type typescript


Step 2. Verify the scaffolding that was created.



Step 3.  Compiling the code.


Step 4. Installing S3 package and adding code for its creations.


Step 5.  Compiling the code and synthesizing the code which is like a dry run of what cloud formation template it will generate and what resources would be created in your account.
Once satisfied deploy using the cdk deploy.




Step 6. Verifying the bucket it had created via AWS Console S3 page.


Step 7. Changing the bucket properties to have S3 bucket encryption enabled via KMS managed.


Step 8. Compiling the code and getting the error of property 'KmsManaged' does not exist as I am referring to the example from AWS documentation which has not kept with the changes of the S3  construct library.



Step 9. Resolving the property 'KmsManaged' issue by making relevant code changes and build it once again.
                           

Step 10.  Using cdk diff to evaluate the difference the changed AWS CDK app and deployed app.
And then deploying it, this will create a AWS cloud formation change set and update the stack.



Step 11.  Again verifying the bucket changes it had done via AWS Console S3 page.



Step 12. Verifying the AWS Cloud formation change set that was run behind the scenes.






Step 14. Destroying the AWS stack via CDK but the resource deletion of S3 was skipped and I had manually deleted the S3 bucket.


Step 15. Verifying the AWS Cloud formation stack no longer exists.



Then via AWS Console, I have deleted the S3 bucket.












Comments

Popular Posts