11package com .amazon .aws .example ;
22
3- import software .amazon .awscdk .core .CfnOutput ;
4- import software .amazon .awscdk .core .CfnOutputProps ;
5- import software .amazon .awscdk .core .Construct ;
6- import software .amazon .awscdk .core .Duration ;
7- import software .amazon .awscdk .core .Stack ;
8- import software .amazon .awscdk .core .StackProps ;
9- import software .amazon .awscdk .services .apigatewayv2 .AddRoutesOptions ;
10- import software .amazon .awscdk .services .apigatewayv2 .HttpApi ;
11- import software .amazon .awscdk .services .apigatewayv2 .HttpApiProps ;
12- import software .amazon .awscdk .services .apigatewayv2 .HttpMethod ;
13- import software .amazon .awscdk .services .apigatewayv2 .PayloadFormatVersion ;
14- import software .amazon .awscdk .services .apigatewayv2 .integrations .LambdaProxyIntegration ;
15- import software .amazon .awscdk .services .apigatewayv2 .integrations .LambdaProxyIntegrationProps ;
16- import software .amazon .awscdk .services .dynamodb .Attribute ;
17- import software .amazon .awscdk .services .dynamodb .AttributeType ;
18- import software .amazon .awscdk .services .dynamodb .BillingMode ;
19- import software .amazon .awscdk .services .dynamodb .Table ;
20- import software .amazon .awscdk .services .dynamodb .TableProps ;
21- import software .amazon .awscdk .services .lambda .*;
3+ import software .amazon .awscdk .*;
4+ import software .amazon .awscdk .services .apigateway .LambdaIntegration ;
5+ import software .amazon .awscdk .services .apigateway .RestApi ;
6+ import software .amazon .awscdk .services .apigateway .RestApiProps ;
7+ import software .amazon .awscdk .services .dynamodb .*;
8+ import software .amazon .awscdk .services .lambda .Code ;
9+ import software .amazon .awscdk .services .lambda .Function ;
10+ import software .amazon .awscdk .services .lambda .FunctionProps ;
2211import software .amazon .awscdk .services .lambda .Runtime ;
2312import software .amazon .awscdk .services .logs .RetentionDays ;
13+ import software .constructs .Construct ;
2414
25- import java .util .HashMap ;
2615import java .util .Map ;
2716
28- import static java .util .Collections .singletonList ;
29-
3017public class InfrastructureStack extends Stack {
3118 public InfrastructureStack (final Construct scope , final String id ) {
3219 this (scope , id , null );
@@ -35,18 +22,17 @@ public InfrastructureStack(final Construct scope, final String id) {
3522 public InfrastructureStack (final Construct scope , final String id , final StackProps props ) {
3623 super (scope , id , props );
3724
38- Table exampleTable = new Table (this , "ExampleTable" , TableProps .builder ()
25+ var exampleTable = new Table (this , "ExampleTable" , TableProps .builder ()
3926 .partitionKey (Attribute .builder ()
4027 .type (AttributeType .STRING )
4128 .name ("id" ).build ())
4229 .billingMode (BillingMode .PAY_PER_REQUEST )
4330 .build ());
4431
45- Function customJava18Function = new Function (this , "LambdaCustomRuntimeJava18" , FunctionProps .builder ()
32+ var customJava18Function = new Function (this , "LambdaCustomRuntimeJava18" , FunctionProps .builder ()
4633 .functionName ("custom-runtime-java-18" )
4734 .handler ("com.amazon.aws.example.ExampleDynamoDbHandler::handleRequest" )
4835 .runtime (Runtime .PROVIDED_AL2 )
49- .architecture (Architecture .X86_64 )
5036 .code (Code .fromAsset ("../runtime.zip" ))
5137 .memorySize (512 )
5238 .environment (Map .of ("TABLE_NAME" , exampleTable .getTableName ()))
@@ -56,21 +42,16 @@ public InfrastructureStack(final Construct scope, final String id, final StackPr
5642
5743 exampleTable .grantWriteData (customJava18Function );
5844
59- HttpApi httpApi = new HttpApi (this , "ExampleApi" , HttpApiProps .builder ()
60- .apiName ("ExampleApi" )
45+ var restApi = new RestApi (this , "ExampleApi" , RestApiProps .builder ()
46+ .restApiName ("ExampleApi" )
6147 .build ());
6248
63- httpApi .addRoutes (AddRoutesOptions .builder ()
64- .path ("/custom-runtime" )
65- .methods (singletonList (HttpMethod .POST ))
66- .integration (new LambdaProxyIntegration (LambdaProxyIntegrationProps .builder ()
67- .handler (customJava18Function )
68- .payloadFormatVersion (PayloadFormatVersion .VERSION_2_0 )
69- .build ()))
70- .build ());
49+ restApi .getRoot ()
50+ .addResource ("custom-runtime" )
51+ .addMethod ("POST" , new LambdaIntegration (customJava18Function ));
7152
7253 new CfnOutput (this , "api-endpoint" , CfnOutputProps .builder ()
73- .value (httpApi . getApiEndpoint ())
54+ .value (restApi . getUrl ())
7455 .build ());
7556 }
7657}
0 commit comments