AWS CDK Using Python as language type

In this, I will cover how we can use Python as a programming language fro AWS CDK. As mentioned earlier since AWS CDK is still in developer preview it has lots of breaking changes between different release version. So my this POC has been done in CDK version 0.39.0 (build c3a3c88).
Initially, I was using  Python 3.5, but I had got issue while running cdk commands. So, in the Gitter discussion of aws-cdk (https://gitter.im/awslabs/aws-cdk), then someone pointed out that it is working fine in his environment which has Python version 3.7, so when I had upgraded my local vagrant environment of Python from 3.5 to 3.7 my cdk setup was also working as expected.
Also, later on I find out out that AWS has mentioned that it will work only with Python version > = 3.6.
Below, I have given the screen shot of how I had setup AWS CDK for Python language by referring to AWS CDK documentation (https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html) and with some modification in the code snippet as AWS documentation also have not kept pace with the CDK version releases, I was able to make CDK work with Python implementation.

Their are some prerequisite of AWS CDK, which I have mentioned previously. Please refer to my earlier blog on CDK with Typescript for smooth experience.

Step 1. Creating application directory and Initializing the application.


Step 2. Creating virtual environment of Python.


Step 3. Activating Python virtual environment and  installing the required dependencies.


Step 4.  Verifying the project structure 



Step 5. Listing the Stack that would be created by the application and installing Amazons-S3 package via pip.



Step 6. Adding the AWS s3 code creation logic, make sure of code have proper indentation as in Python indention in term space is quite important and after that verify the AWS Stack by running cdk synth.



Step 7.  The CDK output is stored in the cdk.out directory and we can verify the AWS Cloud formation there too.



Step 8. Deploying the Stack via cdk deploy



Step 9. Verifying in the Cloud formation console the stack that was created.



Step 10.  Modifying the Stack via application, and evaluating the difference between the deployed stack and the changed Stack using cdk diff. 



Step 11. Then deploying the changed stack. 



Step 12. Verifying the deployed changes in the AWS cloud formation console.



Step 13. Deleting the Stack.



Step 14. Verifying the deletion in the AWS cloud formation console.



Since the Bucket deletion policy was RETAIN, I have manually deleted the bucket.

Comments

Popular Posts