AWS CDK (Cloud Development Kit) is an open-source software development framework for defining cloud infrastructure in code and provisioning it through AWS CloudFormation. It allows developers to use familiar programming languages and deploy cloud applications using AWS resources.
AWS SDK (Software Development Kit) is a collection of tools that enables developers to build software applications that make use of AWS services. It provides APIs (Application Programming Interfaces) for a variety of programming languages, allowing developers to integrate AWS functionality into their applications.
In summary, AWS CDK is a framework for defining and provisioning cloud infrastructure, while AWS SDK is a set of tools for building software applications that use AWS services. You can use both CDK and SDK together to build cloud applications on AWS.
Here are some code examples to show the difference between using AWS CDK and AWS SDK to perform similar tasks.
Using AWS CDK to create an Amazon S3 bucket:
import * as cdk from 'aws-cdk-lib';
import * as s3 from 'aws-cdk-lib/aws-s3';
class MyStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
new s3.Bucket(this, 'MyBucket', {
bucketName: 'my-bucket-name',
versioned: true,
publicReadAccess: false
});
}
}
Using AWS SDK for JavaScript to create an Amazon S3 bucket:
const AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create S3 service object
const s3 = new AWS.S3({apiVersion: '2006-03-01'});
const bucketParams = {
Bucket: 'my-bucket-name',
CreateBucketConfiguration: {
LocationConstraint: 'REGION'
}
};
// Create the bucket
s3.createBucket(bucketParams, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Success", data.Location);
}
});
As you can see, AWS CDK provides a higher-level interface for defining and provisioning cloud resources, while AWS SDK provides more granular control over the individual API calls being made to the AWS services.