-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from CloudBytes-Academy/article
ART: update CDK app
- Loading branch information
Showing
4 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.