11package software .amazon .awscdk .examples ;
22
3- import java .nio .file .*;
4-
53import java .util .Map ;
4+ import java .util .UUID ;
65
76import software .constructs .Construct ;
87import software .amazon .awscdk .CustomResource ;
98import software .amazon .awscdk .Duration ;
10- import java .util .UUID ;
119import software .amazon .awscdk .customresources .*;
1210
1311import software .amazon .awscdk .services .logs .*;
1412import software .amazon .awscdk .services .lambda .Runtime ;
15- import software .amazon .awscdk .services .lambda .InlineCode ;
13+ import software .amazon .awscdk .services .lambda .Code ;
1614import software .amazon .awscdk .services .lambda .SingletonFunction ;
1715
1816public class MyCustomResource extends Construct {
1917 public String response = "" ;
18+
2019 public MyCustomResource (final Construct scope , final String id , final Map <String , ? extends Object > props ) {
2120 super (scope , id );
2221
23-
2422 try {
23+ final SingletonFunction onEvent = SingletonFunction .Builder .create (this , "Singleton1" )
24+ .uuid (UUID .randomUUID ().toString ())
25+ .code (Code .fromAsset ("./asset/lambda-1.0.0-jar-with-dependencies.jar" ))
26+ .handler ("software.amazon.awscdk.examples.CustomResourceHandler" )
27+ .runtime (Runtime .JAVA_21 ).memorySize (1024 )
28+ .timeout (Duration .minutes (5 ))
29+ .build ();
2530
26- final SingletonFunction onEvent = SingletonFunction .Builder .create (this , "Singleton" )
27- .code (InlineCode .fromAsset ("lambda" ))
28- .handler ("custom-resource-handler.on_event" )
29- .runtime (Runtime .PYTHON_3_8 )
31+ final SingletonFunction isComplete = SingletonFunction .Builder .create (this , "Singleton2" )
3032 .uuid (UUID .randomUUID ().toString ())
31- .timeout (Duration .minutes (1 ))
33+ .code (Code .fromAsset ("./asset/lambda-1.0.0-jar-with-dependencies.jar" ))
34+ .handler ("software.amazon.awscdk.examples.CustomResourceIsCompleteHandler" )
35+ .runtime (Runtime .JAVA_21 ).memorySize (1024 )
36+ .timeout (Duration .minutes (5 ))
3237 .build ();
3338
3439 final Provider myProvider = Provider .Builder .create (this , "MyProvider" )
3540 .onEventHandler (onEvent )
41+ .isCompleteHandler (isComplete )
3642 .logRetention (RetentionDays .ONE_DAY )
3743 .build ();
3844
@@ -41,19 +47,10 @@ public MyCustomResource(final Construct scope, final String id, final Map<String
4147 .properties (props )
4248 .build ();
4349
44- response = resource .getAtt ("Response" ). toString ( );
50+ response = resource .getAttString ("Response" );
4551
4652 } catch (Exception e ) {
4753 e .printStackTrace ();
4854 }
4955 }
50- // function to read the file content
51- public static String readFileAsString (String fileName ) throws Exception {
52- try {
53- return new String (Files .readAllBytes (Paths .get (fileName )), "UTF-8" );
54- } catch (Exception e ) {
55- e .printStackTrace ();
56- throw e ;
57- }
58- }
5956}
0 commit comments