Skip to content

Latest commit

 

History

History
122 lines (90 loc) · 5.7 KB

gettingstartedwithcdk.md

File metadata and controls

122 lines (90 loc) · 5.7 KB

First, let us understand "How to Get Started with AWS CDK" to work with the current project:

GETTING STARTED WITH AWS CDK

CDK (Cloud Development Kit) is a framework for defining cloud infrastructure as code and provisioning it through Cloud Formation templates. You can connect your AWS resources together (even across Stacks) and grant permissions using simple, intent-oriented API's. In short, it is defined as "cloud infrastructure as code", i.e., provisioning cloud infrastructure using programming languages. CDK supports: TypeScript, JavaScript,Python, Java, C#/.Net, and Go languages For more information and documentation about CDK, refer to: "https://docs.aws.amazon.com/cdk/v2/guide/home.html"

Getting started with AWS CDK includes the following steps:

STEP 1: PREREQUISITES

Before you begin, make sure you have the following prerequisites in place:

An AWS account: You'll need an AWS account to use AWS CDK.

AWS CLI: Install the AWS Command Line Interface (CLI) and configure it with your AWS credentials. You can download and install it from the AWS CLI website: "https://aws.amazon.com/cli/"

Node.js and npm: AWS CDK uses Node.js for its CLI. You can download Node.js from the official website: "https://nodejs.org/"

STEP 2 : Install AWS CDK

Open a terminal or command prompt and install AWS CDK globally using npm:

npm install -g aws-cdk

Verify that AWS CDK is installed correctly (version) by running:

cdk --version

STEP 3 : Configure AWS CDK

AWS CDK uses the AWS CLI's configuration to access your AWS account. Make sure you've already configured the AWS CLI using aws configure. If not, run:

aws configure

You'll be prompted to enter your AWS Access Key ID, Secret Access Key, default region, and output format. For more help on CLI, refer to: "https://docs.aws.amazon.com/pdfs/cli/latest/userguide/aws-cli.pdf#cli-chap-getting-started"

STEP 4 : Create a CDK App

Now, let's create our first CDK app. We will use the following command to get started:

cdk init app --language=python

Replace Python with your preferred programming language if you prefer a different one (e.g., typescript, javascript, etc.).

STEP 5 : Navigate to your CDK App Directory

Change your current working directory to the newly created CDK app folder:

cd <your-app-name>

STEP 6 : Define AWS CDK Stacks

AWS CDK projects consist of one or more "stacks." A stack is a set of AWS resources that are created and managed together. You can define your stacks in the lib/<app-name>-stack.ts (or .js or .py, depending on your chosen language) file. So,an example Python CDK stack definition in lib/<app-name>-stack.py:

 from aws_cdk import core

class MyCdkStack(core.Stack):

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

        # Define AWS resources here
        # For example, create an S3 bucket:
        from aws_cdk import aws_s3 as s3
        bucket = s3.Bucket(
            self,
            "MyCdkBucket",
            versioned=True,
        )

STEP 7 : Deploy the Stack

Deploy your CDK stack to create AWS resources. Run the following command from your CDK app's root directory:

cdk deploy

CDK will provide a preview of the changes to be made and ask for confirmation. Type 'y' to proceed.

STEP 8 : Explore and Manage your CDK Stack

You can now explore your AWS resources in the AWS Management Console or manage them programmatically using CDK.

STEP 9 : Cleanup (Optional)

If you want to remove the resources created by your CDK stack, run:

cdk destroy

This will delete the AWS resources but won't remove the CDK app itself.

And Boom! You've created your first AWS CDK app and deployed a stack. You can continue to define more stacks, integrate with other AWS services, and use CDK to manage your infrastructure as code (IaC).

Some useful resources or links:

  1. API reference: "https://docs.aws.amazon.com/cdk/api/v2"
  2. CDK workshop: "https://cdkworkshop.com/"
  3. Community hub: "https://cdk.dev/" - including a slack channel
  4. AWS CDK examples: "https://github.com/aws-samples/aws-cdk-examples"
  5. CDK patterns: "https://cdkpatterns.com/"
  6. Aweome CDK: "https://github.com/kolomied/awesome-cdk
  7. AWS solutions constructs: "http://aws.amazon.com/solutions/constructs/
  8. AWS developer blog: "https://aws.amazon.com/blogs/developer/category/developer-tools/aws-cloud-development-kit"
  9. Stack overflow: "https://stackoverflow.com/questions/tagged/aws-cdk"
  10. Github repository: "https://github.com/awslabs/aws-cdk" Issues: "https://github.com/awslabs/aws-cdk/issues" Examples: "https://github.com/aws-samples/aws-cdk-examples" Documentation store: "https://github.com/awsdocs/aws-cdk-guide" Licence: "https://github.com/awslabs/aws-cdk/blob/main/LICENSE" Releases: "https://github.com/awslabs/aws-cdk/releases"
  11. AWS CDK sample for Cloud 9: "https://docs.aws.amazon.com/cloud9/latest/user-guide/sample-cdk.html"
  12. AWS Cloud Formation concepts: "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-whatis-concepts.html"
  13. AWS Glossary: "https://docs.aws.amazon.com/general/latest/gr/glos-chap.html"

Resources for serverless apps with CDK

These tools can work with the AWS CDK to simplify serverless application development and deployment.

  1. AWS Serverless application model: "http://aws.amazon.com/serverless/sam/"
  2. A python serverless microframework: "https://github.com/aws/chalice"