Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ interface ConstructorBuildProps {
readonly optionalConstructorProps?: boolean;

/**
* Visbility for the constructor.
* Visibility for the constructor.
*
* @default MemberVisbility.Public
* @default MemberVisibility.Public
*/
readonly constructorVisbility?: MemberVisibility;
readonly constructorVisibility?: MemberVisibility;

/**
* These statements are added to the constructor body in the order they appear in this property.
Expand Down Expand Up @@ -98,6 +98,13 @@ export interface HandlerFrameworkClassProps {
* @default - the latest Lambda runtime available in the region.
*/
readonly runtime?: Runtime;

/**
* Visibility for the constructor.
*
* @default MemberVisibility.Public
*/
readonly constructorVisibility?: MemberVisibility;
}

interface BuildRuntimePropertyOptions {
Expand Down Expand Up @@ -134,13 +141,13 @@ export abstract class HandlerFrameworkClass extends ClassType {
['runtime', this.buildRuntimeProperty(scope, { runtime: props.runtime })],
]);
const metadataStatements: Statement[] = [
expr.directCode(`this.node.addMetadata('${CUSTOM_RESOURCE_RUNTIME_FAMILY}', this.runtime.family)`),
stmt.directCode(`this.node.addMetadata('${CUSTOM_RESOURCE_RUNTIME_FAMILY}', this.runtime.family)`),
];
this.buildConstructor({
constructorPropsType: LAMBDA_MODULE.FunctionOptions,
superProps,
optionalConstructorProps: true,
constructorVisbility: MemberVisibility.Public,
constructorVisibility: MemberVisibility.Public,
statements: metadataStatements,
});
}
Expand Down Expand Up @@ -226,16 +233,16 @@ export abstract class HandlerFrameworkClass extends ClassType {
['runtime', this.buildRuntimeProperty(scope, { runtime: props.runtime, isEvalNodejsProvider })],
]);
const metadataStatements: Statement[] = [
expr.directCode(`this.addMetadata('${CUSTOM_RESOURCE_SINGLETON}', true)`),
expr.directCode(`this.addMetadata('${CUSTOM_RESOURCE_RUNTIME_FAMILY}', this.runtime.family)`),
expr.directCode(`if (props?.logGroup) { this.logGroup.node.addMetadata('${CUSTOM_RESOURCE_SINGLETON_LOG_GROUP}', true) }`),
stmt.directCode(`this.addMetadata('${CUSTOM_RESOURCE_SINGLETON}', true)`),
stmt.directCode(`this.addMetadata('${CUSTOM_RESOURCE_RUNTIME_FAMILY}', this.runtime.family)`),
stmt.directCode(`if (props?.logGroup) { this.logGroup.node.addMetadata('${CUSTOM_RESOURCE_SINGLETON_LOG_GROUP}', true) }`),
// We need to access the private `_logRetention` custom resource, the only public property - `logGroup` - provides an ARN reference to the resource, instead of the resource itself.
expr.directCode(`if (props?.logRetention) { ((this as any).lambdaFunction as lambda.Function)._logRetention?.node.addMetadata('${CUSTOM_RESOURCE_SINGLETON_LOG_RETENTION}', true) }`),
stmt.directCode(`if (props?.logRetention) { ((this as any).lambdaFunction as lambda.Function)._logRetention?.node.addMetadata('${CUSTOM_RESOURCE_SINGLETON_LOG_RETENTION}', true) }`),
];
this.buildConstructor({
constructorPropsType: _interface.type,
superProps,
constructorVisbility: MemberVisibility.Public,
constructorVisibility: MemberVisibility.Public,
statements: metadataStatements,
});
}
Expand Down Expand Up @@ -337,11 +344,11 @@ export abstract class HandlerFrameworkClass extends ClassType {
isCustomResourceProvider: true,
})],
]);
const metadataStatements: Statement[] = [expr.directCode(`this.node.addMetadata('${CUSTOM_RESOURCE_PROVIDER}', true)`)];
const metadataStatements: Statement[] = [stmt.directCode(`this.node.addMetadata('${CUSTOM_RESOURCE_PROVIDER}', true)`)];
this.buildConstructor({
constructorPropsType: CORE_MODULE.CustomResourceProviderOptions,
superProps,
constructorVisbility: MemberVisibility.Private,
constructorVisibility: props.constructorVisibility ?? MemberVisibility.Private,
optionalConstructorProps: true,
statements: metadataStatements,
});
Expand Down Expand Up @@ -370,7 +377,7 @@ export abstract class HandlerFrameworkClass extends ClassType {

private buildConstructor(props: ConstructorBuildProps) {
const init = this.addInitializer({
visibility: props.constructorVisbility,
visibility: props.constructorVisibility,
});
const scope = init.addParameter({
name: 'scope',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable import/no-extraneous-dependencies */
import * as path from 'path';
/* eslint-disable import/no-extraneous-dependencies */
import { MemberVisibility } from '@cdklabs/typewriter';

/**
* Handler framework runtimes used for code generation.
Expand Down Expand Up @@ -97,6 +98,13 @@ export interface ComponentProps {
* @default true
*/
readonly minifyAndBundle?: boolean;

/**
* Visibility for the constructor.
*
* @default MemberVisibility.Public
*/
readonly constructorVisibility?: MemberVisibility;
}

export type HandlerFrameworkConfig = { [module: string]: { [identifier: string]: ComponentProps[] } };
Expand Down Expand Up @@ -341,6 +349,7 @@ export const config: HandlerFrameworkConfig = {
{
type: ComponentType.CUSTOM_RESOURCE_PROVIDER,
sourceCode: path.resolve(__dirname, '..', 'core', 'cross-region-ssm-writer-handler', 'index.ts'),
constructorVisibility: MemberVisibility.Public,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is changing because the generated class is extended by another class. Previously due to a bug in @cdklabs/typewriter, the generated classes ended up with a public constructor instead of a private one as intended. After the dependency update this failed for the one case, which we make public again to satisfy the compiler.

},
],
'cross-region-ssm-reader-provider': [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class HandlerFrameworkModule extends Module {
handler,
codeDirectory,
runtime: component.runtime,
constructorVisibility: component.constructorVisibility,
};

switch (component.type) {
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/custom-resource-handlers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@types/jest": "^29.5.14",
"aws-sdk-client-mock": "4.1.0",
"aws-sdk-client-mock-jest": "4.1.0",
"@cdklabs/typewriter": "^0.0.6",
"@cdklabs/typewriter": "^0.0.10",
"jest": "^29.7.0",
"sinon": "^9.2.4",
"nock": "^13.5.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export class TestProvider extends CustomResourceProviderBase {
return existing ?? new TestProvider(stack, id, props);
}

public constructor(scope: Construct, id: string, props?: CustomResourceProviderOptions) {
private constructor(scope: Construct, id: string, props?: CustomResourceProviderOptions) {
super(scope, id, {
...props,
"codeDirectory": path.join(__dirname, 'my-handler'),
"runtimeName": determineLatestNodeRuntimeName(scope)
codeDirectory: path.join(__dirname, 'my-handler'),
runtimeName: determineLatestNodeRuntimeName(scope)
});
this.node.addMetadata('aws:cdk:is-custom-resource-handler-customResourceProvider', true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export class TestProvider extends CustomResourceProviderBase {
return existing ?? new TestProvider(stack, id, props);
}

public constructor(scope: Construct, id: string, props?: CustomResourceProviderOptions) {
private constructor(scope: Construct, id: string, props?: CustomResourceProviderOptions) {
super(scope, id, {
...props,
"codeDirectory": path.join(__dirname, 'my-handler'),
"runtimeName": determineLatestNodeRuntimeName(scope)
codeDirectory: path.join(__dirname, 'my-handler'),
runtimeName: determineLatestNodeRuntimeName(scope)
});
this.node.addMetadata('aws:cdk:is-custom-resource-handler-customResourceProvider', true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export class TestFunction extends lambda.Function {
public constructor(scope: Construct, id: string, props?: lambda.FunctionOptions) {
super(scope, id, {
...props,
"code": lambda.Code.fromAsset(path.join(__dirname, 'my-handler')),
"handler": "index.handler",
"runtime": lambda.determineLatestNodeRuntime(scope)
code: lambda.Code.fromAsset(path.join(__dirname, 'my-handler')),
handler: "index.handler",
runtime: lambda.determineLatestNodeRuntime(scope)
});
this.node.addMetadata('aws:cdk:is-custom-resource-handler-runtime-family', this.runtime.family);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export class TestSingletonFunction extends lambda.SingletonFunction {
public constructor(scope: Construct, id: string, props: TestSingletonFunctionProps) {
super(scope, id, {
...props,
"code": lambda.Code.fromAsset(path.join(__dirname, 'my-handler')),
"handler": "index.handler",
"runtime": lambda.determineLatestNodeRuntime(scope)
code: lambda.Code.fromAsset(path.join(__dirname, 'my-handler')),
handler: "index.handler",
runtime: lambda.determineLatestNodeRuntime(scope)
});
this.addMetadata('aws:cdk:is-custom-resource-handler-singleton', true);
this.addMetadata('aws:cdk:is-custom-resource-handler-runtime-family', this.runtime.family);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export class TestProvider extends CustomResourceProviderBase {
return existing ?? new TestProvider(stack, id, props);
}

public constructor(scope: Construct, id: string, props?: CustomResourceProviderOptions) {
private constructor(scope: Construct, id: string, props?: CustomResourceProviderOptions) {
super(scope, id, {
...props,
"codeDirectory": path.join(__dirname, 'my-handler'),
"runtimeName": "python3.11"
codeDirectory: path.join(__dirname, 'my-handler'),
runtimeName: "python3.11"
});
this.node.addMetadata('aws:cdk:is-custom-resource-handler-customResourceProvider', true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export class TestProvider extends CustomResourceProviderBase {
return existing ?? new TestProvider(stack, id, props);
}

public constructor(scope: Construct, id: string, props?: CustomResourceProviderOptions) {
private constructor(scope: Construct, id: string, props?: CustomResourceProviderOptions) {
super(scope, id, {
...props,
"codeDirectory": path.join(__dirname, 'my-handler'),
"runtimeName": "python3.11"
codeDirectory: path.join(__dirname, 'my-handler'),
runtimeName: "python3.11"
});
this.node.addMetadata('aws:cdk:is-custom-resource-handler-customResourceProvider', true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export class TestFunction extends lambda.Function {
public constructor(scope: Construct, id: string, props?: lambda.FunctionOptions) {
super(scope, id, {
...props,
"code": lambda.Code.fromAsset(path.join(__dirname, 'my-handler')),
"handler": "index.handler",
"runtime": lambda.Runtime.PYTHON_3_11
code: lambda.Code.fromAsset(path.join(__dirname, 'my-handler')),
handler: "index.handler",
runtime: lambda.Runtime.PYTHON_3_11
});
this.node.addMetadata('aws:cdk:is-custom-resource-handler-runtime-family', this.runtime.family);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export class TestSingletonFunction extends lambda.SingletonFunction {
public constructor(scope: Construct, id: string, props: TestSingletonFunctionProps) {
super(scope, id, {
...props,
"code": lambda.Code.fromAsset(path.join(__dirname, 'my-handler')),
"handler": "index.handler",
"runtime": lambda.Runtime.PYTHON_3_11
code: lambda.Code.fromAsset(path.join(__dirname, 'my-handler')),
handler: "index.handler",
runtime: lambda.Runtime.PYTHON_3_11
});
this.addMetadata('aws:cdk:is-custom-resource-handler-singleton', true);
this.addMetadata('aws:cdk:is-custom-resource-handler-runtime-family', this.runtime.family);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export class EvalNodejsSingletonFunction extends lambda.SingletonFunction {
public constructor(scope: Construct, id: string, props: EvalNodejsSingletonFunctionProps) {
super(scope, id, {
...props,
"code": lambda.Code.fromAsset(path.join(__dirname, 'my-handler')),
"handler": "index.handler",
"runtime": (props.runtime ? props.runtime : lambda.determineLatestNodeRuntime(scope))
code: lambda.Code.fromAsset(path.join(__dirname, 'my-handler')),
handler: "index.handler",
runtime: (props.runtime ? props.runtime : lambda.determineLatestNodeRuntime(scope))
});
this.addMetadata('aws:cdk:is-custom-resource-handler-singleton', true);
this.addMetadata('aws:cdk:is-custom-resource-handler-runtime-family', this.runtime.family);
Expand Down
2 changes: 1 addition & 1 deletion tools/@aws-cdk/cdk-build-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"glob": "^7.2.3",
"jest": "^29.7.0",
"jest-junit": "^13.2.0",
"jsii": "~5.9.8",
"jsii": "~5.9.13",
"jsii-rosetta": "~5.9.9",
"jsii-pacmak": "1.118.0",
"jsii-reflect": "1.118.0",
Expand Down
2 changes: 1 addition & 1 deletion tools/@aws-cdk/spec2cdk/lib/cdk/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export class AstBuilder {
return ret;
}

private createResourceModule(moduleName: string, serviceName: string, importLocations?: ModuleImportLocations) {
protected createResourceModule(moduleName: string, serviceName: string, importLocations?: ModuleImportLocations) {
const resourceModule = new Module(`@aws-cdk/${moduleName}/${serviceName}`);
CDK_CORE.import(resourceModule, 'cdk', { fromLocation: importLocations?.core });
CONSTRUCTS.import(resourceModule, 'constructs');
Expand Down
5 changes: 2 additions & 3 deletions tools/@aws-cdk/spec2cdk/lib/cdk/relationship-decider.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Property, RelationshipRef, Resource, RichProperty, SpecDatabase } from '@aws-cdk/service-spec-types';
import { namespaceFromResource, referenceInterfaceName, referenceInterfaceAttributeName, referencePropertyName, typeAliasPrefixFromResource } from '../naming';
import { getReferenceProps } from './reference-props';
import { createModuleDefinitionFromCfnNamespace } from '../cfn2ts/pkglint';
import { log } from '../util';
import { log, pkglint } from '../util';

// For now we want relationships to be applied only for these services
export const RELATIONSHIP_SERVICES: string[] = [];
Expand Down Expand Up @@ -55,7 +54,7 @@ export class RelationshipDecider {
originalType: string;
aliasedType: string;
}) {
const moduleName = createModuleDefinitionFromCfnNamespace(namespace).moduleName;
const moduleName = pkglint.createModuleDefinitionFromCfnNamespace(namespace).moduleName;
const moduleImport = this.imports.find(i => i.moduleName === moduleName);
if (!moduleImport) {
this.imports.push({
Expand Down
34 changes: 1 addition & 33 deletions tools/@aws-cdk/spec2cdk/lib/cdk/resource-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
TruthyOr,
Type,
TypeDeclarationStatement,
DocsSpec,
} from '@cdklabs/typewriter';
import { CDK_CORE, CONSTRUCTS } from './cdk';
import { CloudFormationMapping } from './cloudformation-mapping';
Expand All @@ -39,7 +38,7 @@ import {
staticRequiredTransform,
staticResourceTypeName,
} from '../naming';
import { splitDocumentation } from '../util';
import { isDefined, splitDocumentation, maybeDeprecated } from '../util';
import { findArnProperty } from './reference-props';
import { SelectiveImport, RelationshipDecider } from './relationship-decider';

Expand Down Expand Up @@ -640,37 +639,6 @@ export class ResourceClass extends ClassType {
}
}

/**
* Type guard to filter out undefined values.
*/
function isDefined<T>(x: T | undefined): x is T {
return x !== undefined;
}

/**
* Compute stability taking into account deprecation status.
*/
function stability(isDeprecated: boolean = false, defaultStability: Stability = Stability.External): Stability {
if (isDeprecated) {
return Stability.Deprecated;
}
return defaultStability;
}

/**
* Returns deprecation props if deprecated.
*/
function maybeDeprecated(deprecationNotice?: string, defaultStability: Stability = Stability.External): Pick<DocsSpec, 'deprecated' | 'stability'> {
if (deprecationNotice) {
return {
deprecated: deprecationNotice,
stability: stability(Boolean(deprecationNotice), defaultStability),
};
}

return {};
}

/**
* Given a template like "arn:${Partition}:ec2:${Region}:${Account}:fleet/${FleetId}",
* and a list of property names, like ["partition", "region", "account", "fleetId"],
Expand Down
1 change: 1 addition & 0 deletions tools/@aws-cdk/spec2cdk/lib/cdk/type-converter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @cdklabs/no-throw-default-error */
import {
SpecDatabase,
PropertyType,
Expand Down
Loading
Loading