AWS CDK vs Serverless Framework for lambda?

Read more about AWS CDK here: https://awslabs.github.io/aws-cdk/

It has some obvious advantages over the serverless framework, most notably that you can write your stack in code. E.g. you can programmatically define that a certain stack should be deployed prior to another one, and you can easily pass references from one to another, which is much easier than relying on hardcoded cross-stack references and then remember whether that updated version of a referenced stack is already deployed or not.

Does anyone have experience with AWS CDK? Do you think it can replace this framework, or if this framework can rely on it or learn from it?

6 Likes

I have posted feature request to integrate with AWS CDK:

1 Like

Yes, just started using it and its a breath of fresh air! If you do anything other than Lambda functions on AWS its so much easier as you just define what you want and it creates all the IAM roles with minimal access permissions. And yes, you can script it so if you have a generic lambda that you call differently, i.e. different environmental vars say, you can loop over an array which contains the differences. You don’t have to write any cloudformation template stuff anymore or dick around with references, its all setup for you, you just have to link the services.
The only draw back is that there is vendor lock in, but it i expect a framework to emerge that abstracts the provider out and does this generically… i mean they pretty much all offer the same stuff.

1 Like

We actually put something together recently at Serverless Stack to helping using Serverless Framework and AWS CDK together. Serverless’s strength is working with Lambda and API Gateway. So a good pattern here is to use CDK for the rest of your infrastructure, and Serverless for your Lambda functions.

So we created a tool to do exactly this - Serverless Stack Toolkit (SST), which allows you to combine CDK and Serverless Framework - https://github.com/serverless-stack/serverless-stack

You can deploy your Serverless service and CDK service like sls deploy --stage dev and sst deploy --stage dev.

3 Likes

Serverless makes it easier to deploy lambdas and other services around lambda ( apigateway, cognito etc etc) . It has few bugs here and there but all in all its very good framework to deploy lambdas. Atleast i found that it takes out lot of burden from developer. This is more of config over coding and i like it.

I used CDK for common infrastructure that’s created only once eg. ApiGateway, RDS, SQS queues, Route53 etc. I was used to writing this as bare cloudformation templates and cdk made it much easier for me.