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?
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/)
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).
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.
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.
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.
© 2022 - 2024 — McMap. All rights reserved.