Skip to content

Commit

Permalink
Merge pull request #160 from CloudBytes-Academy/article
Browse files Browse the repository at this point in the history
ART: update CDK app
  • Loading branch information
rehanhaider authored Oct 22, 2023
2 parents 1963d86 + 6383129 commit d8a9775
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Date: 2023-10-22
Category: AWS Academy
Series: AWS CDK
series_index: 4
Tags: aws, cdk
Tags: aws, cdk, python
Author: Rehan Haider
Summary: How to create a new CDK app that uses Python as the programming language
Keywords: AWS
Expand Down
55 changes: 55 additions & 0 deletions content/aws/50002000-cdk-update-app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Title: Update an existing CDK app
Date: 2023-10-22
Category: AWS Academy
Series: AWS CDK
series_index: 5
Tags: aws, cdk, python
Author: Rehan Haider
Summary: How to update an existing CDK app
Keywords: AWS


In this post, we'll update an existing CDK app that uses Python as the programming language.

If you haven't created a new CDK app yet, follow the steps in [Creating a new CDK app with Python]({filename}50001000-cdk-new-app.md).

!!! note
Ensure that [AWS CDK is installed & configured]({filename}00000100-cdk-installing-cdk-sam-cli.md) before proceeding.

## Updating an existing CDK app

We can simply update the stack bby modifying the `cdk_app/cdk_app_stack.py` file.

For example, we can change the retention policy by modifying the `cdk_app/cdk_app_stack.py` file as follows:

```python

from aws_cdk import (
Stack,
aws_s3 as s3,
RemovalPolicy, # New Import
)

from constructs import Construct

class CdkAppStack(Stack):

BUCKET_NAME = "MyFirstBucket"

def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)

# Updated code. This will delete the bucket when the stack is deleted
s3.Bucket(self, "MyFirstBucket", removal_policy=RemovalPolicy.DESTROY)
```

Check the changes by running `cdk diff`. As you can see below, there is a change in Bucket policy being implemented.

![CDK diff]({static}/images/aws-academy/50002000-cdk-cdk-diff-changes.png)


Now run `cdk deploy` to deploy the changes. When you destroy the stack by running `cdk destroy`, you'll notice that the bucket is deleted as well.




1 change: 0 additions & 1 deletion content/aws/87500000-cdk-api-gateway-route53.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Title: CDK API Gateway with Custom Domain
Date: 2022-10-24
Category: AWS Academy
Series: AWS CDK
Tags: aws, cdk, python
Author: Rehan Haider
Summary: Create API Gateway and connect it with a custom domain / subdomain using Route53
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d8a9775

Please sign in to comment.