Amazon cdk and boto3 difference
Asked Answered
W

5

12

I am new to AWS with python. I came across boto3 initially, later somone suggested cdk. What is the difference between aws cdk and boto3?

Woo answered 4/5, 2021 at 4:47 Comment(0)
C
11

In simple terms, CDK helps you to programmatically create AWS resources(Infrastructure as Code) while boto3 helps you to programmatically access AWS services.

Here is a snippet on CDK and Boto3 from AWS reference links :

CDK:
The AWS Cloud Development Kit (AWS CDK) is an open source software development framework to define your cloud application resources using familiar programming languages. AWS CDK provisions your resources in a safe, repeatable manner through AWS CloudFormation. It also enables you to compose and share your own custom constructs that incorporate your organization's requirements, helping you start new projects faster. (Reference: https://aws.amazon.com/cdk/)

With CDK and Cloudformation, you will get the benefits of repeatable deployment, easy rollback, and drift detection. (Reference: https://aws.amazon.com/cdk/features/)

Boto3:
Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK) for Python, which allows Python developers to write software that makes use of services like Amazon S3 and Amazon EC2. (Reference: https://pypi.org/project/boto3/)

Conde answered 4/5, 2021 at 5:43 Comment(0)
S
4

Welcome to Stack Overflow and to AWS usage!

boto3 is the python SDK for AWS. It is useful in order for your software to be able to elevate other AWS services.

use case example: your code has to put an object in an S3 bucket (store a file in other words).

aws-cdk is a framework that helps you provision infrastructure in an IaC (Infrastructure as Code) manner.

use case example: describe and provision your application infrastructure (e.g. a lambda function and an S3 bucket).

In many projects you will use both.

you can find an example URL shortener that uses boto3 and aws-cdk here. The URL shortener uses boto3 in order to access a DynamoDB table and aws-cdk in order to provision the whole infrastructure (including the lambda function which uses boto3).

Sutlej answered 4/5, 2021 at 5:21 Comment(2)
I can also create my resources using boto3. No? then why CDK?Geniality
@AliMohsan Exactly, Did you specifically find a good reason to use CDK rather than boto3? Please share if any. ThanksTiphane
J
1

You're creating an application that needs to use AWS services and resources. Should you use cdk or boto-3?

Consider if your application needs AWS services and resources at build time or run time.

Build time: you need the AWS resources to be available IN ORDER TO build the application.

Run time: you need the AWS resources to be available via API call when your application is up and running.

AWS CDK setups the infrastructure your application needs in order to run.

AWS SDK compliments your application to provide business logic and to make services available through your application.

Another point to add is that AWS CDK manages the state of your deployed resources internally, thus allowing you to keep track of what has been deployed and to specify the desired state of your final deployed resources.

On the other hand, if you're using AWS SDK, you have to store and manage the state of the deployed resources (deployed using AWS SDK) yourself.

Jaime answered 10/5, 2021 at 5:21 Comment(0)
A
1

I am also new to AWS, here is my understanding for relevant AWS services and boto3

  • AWS Cloud Development Kit (CDK) is a software library, available in different programming languages, to define and provision cloud infrastructure*, through AWS CloudFormation.

  • Boto3 is a Python software development kit (SDK) to create, configure, and manage AWS services.

  • AWS CloudFormation is a low-level service to create a collection of relation AWS and third-party resources, and provision and manage them in an orderly and predictable fashion.

  • AWS Elastic Beanstalk is a high-level service to deploy and run applications in the cloud easily, and sits on top of AWS CloudFormation.

Admix answered 16/9, 2021 at 9:11 Comment(0)
P
0

The CDK is an abstraction over clouformation, which is an abstraction over the AWS API, whereas boto3 allows you to directly consume the AWS API.

Almost everything that cloudformation does, you could implement yourself using boto3. It's really exhaustive.

I say "almost" because it's possible that cloudformation relies on endpoints not exposed publicly by AWS, in which case boto3 wouldn't have them. Remember that cloudformation is not open source and runs internally within AWS. We don't know how it deploys the stack.

Look, for example this is the documentation for boto3/ECS: https://boto3.amazonaws.com/v1/documentation/api/1.9.42/reference/services/ecs.html

It's extremely exhaustive.

Boto3 is imperative and allows you to do anything, including things that have nothing to do with deploying your app on AWS (managing users, auditing, fetching data from AWS, connect to slack or discord, etc, etc...)

Whereas cloudformation is declarative and makes choices for you on how to build your app. It's usually focused on deploying your app and less on helping you build AWS integrations (which boto3 is really good at)

In practice, people use cloudformation to deploy their app because it's vetted by AWS.

But for all the things it can't do, or the things that tend to be custom, you can use boto3. A good example is pushing your static files to S3, because you might want to do it a specific time that YOU control.

Finally, what is the CDK? The CDK is a framework that builds cloudformation code for you. It's one level above cf. And it's made of building blocks that allow you to not worry about Cloudformation.

Cloudformation can be very verbose. The CDK is giving you the tools to build an app in 100 lines, which, if converted in cloudformation, could take 500-1000 lines of code.

The CDK makes choices for you on how to build your cloudformation, and cfn makes the choice for you on how you will consume the AWS API.

Purge answered 14/8 at 22:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.