1- import * as crypto from 'crypto ' ;
1+ import { ResourceAutoNaming , ResourceDefaultNaming , ResourceNaming , ResourceNamingOptions , ResourceNamingType } from '@gammarers/aws-resource-naming ' ;
22import * as cdk from 'aws-cdk-lib' ;
33import * as iam from 'aws-cdk-lib/aws-iam' ;
44import * as cr from 'aws-cdk-lib/custom-resources' ;
@@ -17,26 +17,88 @@ export enum ResponseField {
1717 HOST_ARN = 'HostArn' ,
1818}
1919
20+ //export type Names = {
21+ // functionName: string;
22+ // functionRoleName: string;
23+ //}
24+ //export interface Names {
25+ // readonly functionName: string;
26+ // readonly functionRoleName: string;
27+ //}
28+ //
29+ //export type CustomNaming = {
30+ // type: ResourceNaming.NamingType.CUSTOM;
31+ // // functionName: string;
32+ // // functionRoleName: string;
33+ // names: Names;
34+ //}
35+
36+ //export interface ResourceNamingOptions {
37+ // readonly naming: ResourceNaming.AutoNaming | ResourceNaming.DefaultNaming | {
38+ // type: ResourceNaming.NamingType.CUSTOM;
39+ // names: {
40+ // functionName: string;
41+ // functionRoleName: string;
42+ // };
43+ // };
44+ //}
45+
46+ //export interface ResourceNamingOptions {
47+ // readonly naming: ResourceNaming.AutoNaming | ResourceNaming.DefaultNaming;
48+ //}
49+ //export type Naming = { type: ResourceNaming.NamingType.DEFAULT } | { type: ResourceNaming.NamingType.AUTO } | CustomNaming;
50+ //export type Naming = { type: ResourceNaming.NamingType.DEFAULT } | { type: ResourceNaming.NamingType.AUTO } | CustomNaming;
51+ //export type Naming = CustomNaming;
52+
53+ //export interface ResourceNamingOptions {
54+ // readonly naming: Naming;
55+ //}
56+ //export interface DefaultNamingOption {
57+ // readonly type: ResourceNaming.NamingType.DEFAULT;
58+ //}
59+ //
60+ //export interface AutoNamingOption {
61+ // readonly type: ResourceNaming.NamingType.AUTO;
62+ //}
63+
64+ export interface CustomNaming {
65+ readonly type : ResourceNamingType . CUSTOM ;
66+ // readonly names: Names; // CUSTOM の場合に必須
67+ readonly functionName : string ; // フラット化
68+ readonly functionRoleName : string ; // フラット化
69+ }
70+
71+ export type ResourceNamingOption = ResourceDefaultNaming | ResourceAutoNaming | CustomNaming ;
72+
2073export interface CodeConnectionsHostCustomResourceProps {
2174 readonly name : string ;
2275 readonly providerEndpoint : string ;
2376 readonly providerType : CodeConnectionsHostProviderType ;
77+ //readonly resouceNamingOption?: ResourceNamingOptions;
78+ // readonly resouceNamingOption?: { type: ResourceNaming.NamingType.DEFAULT } | { type: ResourceNaming.NamingType.AUTO } | CustomNaming;
79+ readonly resouceNamingOption ?: ResourceNamingOption ;
2480}
2581
2682export class CodeConnectionsHostCustomResource extends cr . AwsCustomResource {
2783
2884 constructor ( scope : Construct , id : string , props : CodeConnectionsHostCustomResourceProps ) {
2985
3086 // 👇 Create random 8 length string
31- const random : string = crypto . createHash ( 'shake256' , { outputLength : 4 } )
32- . update ( `${ cdk . Names . uniqueId ( scope ) } .${ props . name } .${ props . providerEndpoint } .${ props . providerType } ` )
33- . digest ( 'hex' ) ;
87+ const random = ResourceNaming . createRandomString ( `${ cdk . Names . uniqueId ( scope ) } .${ props . name } .${ props . providerEndpoint } .${ props . providerType } ` ) ;
88+ const autoNaming = {
89+ functionName : `custom-resource-codeconnection-host-${ random } -func` ,
90+ functionRoleName : `custom-resource-codeconnection-host-${ random } -func-exc-role` ,
91+ } ;
92+ const names = ResourceNaming . naming ( autoNaming , props . resouceNamingOption as ResourceNamingOptions ) ;
93+ // const naming = {
94+ // names: autoNaming,
95+ // };
3496
3597 const account = cdk . Stack . of ( scope ) . account ;
3698 const region = cdk . Stack . of ( scope ) . region ;
3799
38100 const functionRole = new iam . Role ( scope , 'FunctionRole' , {
39- roleName : `custom-resource-codeconnection-host- ${ random } -func-exc-role` ,
101+ roleName : names . functionRoleName ,
40102 description : 'Custom Resource Function Execution Role.' ,
41103 assumedBy : new iam . ServicePrincipal ( 'lambda.amazonaws.com' ) ,
42104 managedPolicies : [
@@ -62,10 +124,11 @@ export class CodeConnectionsHostCustomResource extends cr.AwsCustomResource {
62124 } ) ;
63125
64126 super ( scope , id , {
65- functionName : `custom-resource-codeconnection-host- ${ random } -func` ,
127+ functionName : names . functionName ,
66128 role : functionRole ,
67129 timeout : cdk . Duration . seconds ( 15 ) ,
68130 installLatestAwsSdk : true ,
131+ //logGroup: todo
69132 onCreate : {
70133 service : 'CodeConnections' ,
71134 action : 'createHost' ,
0 commit comments