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


In the section, I will explore on using AWS CDK to create AWS resources through the Java programming language.

Here are few requisite on following the steps.

    • Maven 3.5.4 and Java 8
    • Setting JAVA_HOME and maven home.
    • Installing AWS CDK, I am using 0.39.0 (build c3a3c88)
    • Settimg your AWS Region and AWS credentials which I have used while deploying the output (Cloud formation) in my account. 
I have followed Steps from the AWS documentation on AWS CDK https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html.


As mentioned before, AWS CDK is under developer preview so this might not work in the various code releases by AWS as these will be breaking changes.

Step 1. Creating the App directory, Initializing the App as java App and making sure the proxy is set for maven in the settings.xml in case you are running behind the corporate proxy.



Step 2.  Renaming the App as hellocdkStack.


Step 3. Compiling the App after renaming the Stack and listing the Stacks that will be created by cdk ls.
This will only work if your maven setting is configured.




Step 4. Adding S3 dependency in the pom.xml


Step 5. Defining the bucket in the Java file src/main/java/com/myorg/HelloStack.java. The maven dependencies is already defined in the  pox.xml file.


Step 6. Compiling the application after making S3 bucket creation changes. I am getting WARNING because I am having duplicate S3 dependency in pom.xml, which I had latter on removed.


Step 7. Synthesize an AWS Cloud Formation template for the app, which will generate what cloud formation will be deployed.


Step 8 . The same output which was generated by cdk synth command is stored in the cdk.out directory as hellocdkStack.template.json


Step 9. Deploying the stack using cdk deploy.


Step 10. Verifying the stack creation in the AWS Cloud formation console


Step 11. Modifying the Stack so that bucket to use KMS managed encryption.


Step 12. Compiling the application and checking the difference between the modified stack and deployed stack using cdk diff 


It is mentioning that BucketEncryption would added in the MyJavaBucket.

Step 13. Then deploying the modified stack using cdk deploy, during which it will create Cloud formation change set and update the deployed stack.


Step 14. Verifying it in the Cloud formation console and checking the S3 bucket properties.



Step 15. Destroying the App resources using cdk destroy command and verifying the stack in cloud formation console that it is deleted.



After that, I had manually deleted the S3 bucket, as deletion policy was RETAIN. So it had to be manually deleted. 

Comments

Popular Posts