This can be confusing, because "Application" is an overloaded term. The narrow answer is no, no CDK without an App, which is the CDK's root collection of Constructs. But that should not bother you.
Docs: AWS CDK apps are composed of building blocks known as Constructs, which are composed together to form stacks and apps.
More broadly, if the question is "I just want a simple lambda with no extra stuff (or cost!), can I use the CDK?", then yes, of course. The CDK "App" itself is not a deployed resource and has no price.
We can demonstrate this with a minimal, lambda-only stack and the generated CloudFormation template cdk deploy
sends to AWS.
// a minimial lambda stack
// Only a lambda will be created. Not even a role, because we are reusing an existing one (not a best practice, just for illustration)
export class MinimalStack extends cdk.Stack {
constructor(scope: Construct, id: string, props: cdk.StackProps) {
super(scope, id, props);
new lambda.Function(this, 'MyPlaygroundFunction', {
code: new lambda.InlineCode("exports.handler = () => console.log('hello lambda')"),
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'index.handler',
role: iam.Role.fromRoleArn(this, 'MyExistingRole', 'arn:aws:iam::xxxxxxxx8348350:role/xxxxxxxxxxxxx-GI5QDFDJWT0A'),
});
}
}
The template has just 2 resources, the Lambda and an auto-created AWS::CDK::Metadata
used for version reporting:
// CloudFormation template Resource section - the template will be in the cdk.out folder
"Resources": {
"MyPlaygroundFunctionBAD1926E": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": { "ZipFile": "exports.handler = () => console.log('hello lambda')"},
"Role": "arn:aws:iam::xxxxxxxx8348350:role/xxxxxxxxxxxxx-GI5QDFDJWT0A",
"Handler": "index.handler",
"Runtime": "nodejs14.x"
},
"Metadata": {"aws:cdk:path": "TsCdkPlaygroundMinimalStack/MyPlaygroundFunction/Resource"}
},
"CDKMetadata": {
"Type": "AWS::CDK::Metadata",
"Properties": { "Analytics": "v2:deflate64:H4sAAAAA/zWK...."},
"Metadata": { "aws:cdk:path": "TsCdkPlaygroundMinimalStack/CDKMetadata/Default"}
}
},