Reputation: 103
I have a doubt in my mind regarding AWS Amplify and CDK. In Amplify if we can create new environments and publish them to their respective buckets? Why do we need CDK? Any use case that would make CDK a better fit?
Upvotes: 6
Views: 4164
Reputation: 2112
You will find out that you will need to write and edit a lot of CloudFormation templates for a production app. That gets very painful very fast.
Amplify should emit CDK code, that would give us the best of both worlds.
I used Amplify a lot initially as it could bootstrap you quickly, but since discovering CDK, CDK is the tool I use the most.
Upvotes: 0
Reputation: 403
Amplify is ok for deploying static sites, with a simple database and Cognito integration, but it is not good for managing a large number of environments or more complicated stacks. CDK is much better for managing complex infrastructure deployment. This is an example of how you can deploy static sites with CDK. https://github.com/davidsteed/awscdkstaticsite. It improves on what can be done with Amplify by dealing with security headers and certificate generation.
Upvotes: 0
Reputation: 3037
CDK let you deploy (quite) any type of Stack that you have to manually do with cloudformation. Using cdk
, you are going to create a CloudFormation stack more quicly and in a more secure way.
An example in JAVA, in order to create a new Table, you can use the following code instead of deal with YAML configuration:
private Table CreateMasterDataTable(String TABLE_NAME) {
return Table.Builder.create(this, TABLE_NAME + "_MasterDataTable")
.tableName(TABLE_NAME.concat("_gvr-bic-masterdata"))
.partitionKey(Attribute.builder().type(AttributeType.STRING).name("siteId").build())
.removalPolicy(RemovalPolicy.RETAIN)
.stream(StreamViewType.NEW_AND_OLD_IMAGES)
.readCapacity(5)
.writeCapacity(5)
.build();
}
In order to create a new Lambda (provided an alredy existent JAR), you can use the following code instead of deal with YAML configuration:
private Function CreateSiteAggregationNowFunction() {
Map<String, String> env = new HashMap<>();
env.put(Constants.LAMBDA_KEY_ENV, API_NAME);
return Function.Builder.create(this, API_NAME + "_SiteAggregationNow")
.code(Code.fromAsset(Constants.LAMBDA_PATH_SITE_NOW))
.handler("it.fabricalab.gvr.bic.DeviceLoader::handleRequest")
.timeout(Duration.seconds(30))
.environment(env)
.functionName(API_NAME.concat("_SiteAggregationNow"))
.runtime(Runtime.JAVA_8)
.retryAttempts(Constants.LAMBDA_RETRY_FALLBACK)
.memorySize(512)
.build();
}
Than, in order to create the policy for let the lambda read from the table:
final Table masterDataTable = CreateMasterDataTable(API_NAME);
final Function siteAggregationNow = CreateSiteAggregationNowFunction();
masterDataTable .grantReadData(siteAggregationNow);
With these few lines, you have crated a CloudFormation stack with a DynamoDB table (that use stream) and a Lambda that read from this table.
Upvotes: 3