Reputation: 2063
I am using aws-cdk and I would like to declare a Global section as suggested here
How can I create the Globals
section from aws-cdk typescript code?
Parameters:
Tag:
Type: String
Default: latest
Description: Docker tag to build and deploy.
Globals:
Function:
Timeout: 5
The Parameters
section is done.
I wrote this code:
new CfnParameter(this, 'Tag', {
default: 'latest',
description: 'Docker tag to build and deploy.'
});
and I got the desired output.
But I could not find the parallel to Globals
in cdk API.
What code should I use to get the same output of Globals
section?
Upvotes: 2
Views: 1187
Reputation: 41608
Since you're using AWS CDK, I don't think it's a good idea to try to generate a SAM template, even though technically it might be possible using escape hatches.
AWS CDK makes creating, e.g., Lambda functions a piece of cake. IMHO it is simpler than using AWS SAM. Especially if you have programmer background.
Since AWS CDK uses a regular language, you can use the language default way to define a global variable. For instance in TypeScript:
const SOME_GLOBAL_VARIABLE = 'a secret sauce';
class MyStack extends cdk.Stack {
constructor(scope: Scope, id: string){
new Vpc(this, 'Vpc', {
name: SOME_GLOBAL_VARIABLE
})
}
}
Upvotes: 3
Reputation: 336
Globals
concept is related to SAM. It is to reuse the code in SAM template.
Please mind CDK does not generate SAM template, but rather pure cloudformation template. Both SAM and CDK generate cloudformation templates and are rather overlapping technologies.
In short, you can not generate Globals
section with CDK because there is no such conecpt in Cloudformation.
If you wish to reuse some code, you can anyway reuse variables with the programing language that you are using with CDK.
Upvotes: 3