Create an IAM User with AdministratorAccess
policy.
Install AWS Cli, Go to IAM User and Security credentials
, Access Key, Create Access Key.
aws configure
Enter Values and Output format as json
.
Stacks are way to organize resources.
Upload a simple JSON.
{
"Resources": {
"HelloBucket": {
"Type": "AWS::S3::Bucket",
"Properties": {
"AccessControl": "PublicRead"
}
}
}
}
Install CDK
npm i -g aws-cdk
Initialize CDK
cdk init --language=typescript
cdk.json cdk configuration file.
Inside Project root folder run cdk bootstrap
.
Check CloudFormation
View in AWS console.
Now run cdk deploy
Check CloudFormation, it will add CDKStarterStack
and inside resources it will have CDKMetadata
.
Check cdk.out` folder in root folder of the project, which is deployed in the AWS Stacks.
cdk synth
will only generate template files but does not deploy, so do cdk synth && cdk deploy
There are 3 level of CDK constructs
- L1: Low level constructs - (Cloud formation) resources. When used, we must configure all properties. (Most AWS resources are migrated to L2)
- L2: AWS resources with higher-level - CDK provides additional functionality like defaults, boiler plate and type safety for many parameters. (Most of the time)
- L3: Patterns: Combine multiple types of resouces and help with common tasks in AWS. Examples: LambdaRestApi (Matter of preference of company policy. What degree of abstraction do I want?)
cdk list
Shows you difference between your local and deployed on AWS.
cdk diff
cdk doctor
Destroy Stack from AWS
cdk destroy CdkStarterStack
const myL2Bucket = new Bucket(this, 'MyL2Bucket', {
lifecycleRules: [{
expiration: Duration.days(2)
}]
});
new CfnOutput(this, 'MyL2BucketName', { // This outputs in AWS Outputs Section to debug once deployed.
value: myL2Bucket.bucketName
});
new CfnParameter(this, 'duration', {
default: 6,
minValue: 1,
maxValue: 10,
type: 'Number'
});
Now, try firing this command:
cdk deploy --parameters duration=11
You will get an error.