Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between VPC and cfnVPC in AWS CDK?

Both the classes are used to create VPC. Of course, cfn means Cloud formation, but the command "CDK synth" would also convert an aws_ec2.Vpc() into a Cloud formation template right? So what exactly is the difference? Can someone please help me?

like image 926
megh Avatar asked Jan 25 '23 15:01

megh


1 Answers

There are different levels of constructs in CDK:

Low-level constructs, which are called CFN Resources (or L1, short for "level 1") or Cfn resources. These constructs directly represent all resources available in AWS CloudFormation. CFN Resources are periodically generated from the AWS CloudFormation Resource Specification. They are named CfnXyz, where Xyz is name of the resource. For example, CfnBucket represents the AWS::S3::Bucket AWS CloudFormation resource. When you use Cfn resources, you must explicitly configure all resource properties, which requires a complete understanding of the details of the underlying AWS CloudFormation resource model.

The next level of constructs, L2, also represent AWS resources, but with a higher-level, intent-based API. They provide similar functionality, but provide the defaults, boilerplate, and glue logic you'd be writing yourself with a CFN Resource construct. AWS constructs offer convenient defaults and reduce the need to know all the details about the AWS resources they represent, while providing convenience methods that make it simpler to work with the resource. For example, the s3.Bucket class represents an Amazon S3 bucket with additional properties and methods, such as bucket.addLifeCycleRule(), which adds a lifecycle rule to the bucket.

Finally, the AWS Construct Library includes even higher-level constructs, which are called patterns. These constructs are designed to help you complete common tasks in AWS, often involving multiple kinds of resources. For example, the aws-ecs-patterns.ApplicationLoadBalancedFargateService construct represents an architecture that includes an AWS Fargate container cluster employing an Application Load Balancer (ALB). The aws-apigateway.LambdaRestApi construct represents an Amazon API Gateway API that's backed by an AWS Lambda function.

Source: AWS CDK Documentation

like image 67
Dennis Traub Avatar answered Feb 16 '23 19:02

Dennis Traub