1
1
package com .amazon .aws .example ;
2
2
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 ;
22
11
import software .amazon .awscdk .services .lambda .Runtime ;
23
12
import software .amazon .awscdk .services .logs .RetentionDays ;
13
+ import software .constructs .Construct ;
24
14
25
- import java .util .HashMap ;
26
15
import java .util .Map ;
27
16
28
- import static java .util .Collections .singletonList ;
29
-
30
17
public class InfrastructureStack extends Stack {
31
18
public InfrastructureStack (final Construct scope , final String id ) {
32
19
this (scope , id , null );
@@ -35,18 +22,17 @@ public InfrastructureStack(final Construct scope, final String id) {
35
22
public InfrastructureStack (final Construct scope , final String id , final StackProps props ) {
36
23
super (scope , id , props );
37
24
38
- Table exampleTable = new Table (this , "ExampleTable" , TableProps .builder ()
25
+ var exampleTable = new Table (this , "ExampleTable" , TableProps .builder ()
39
26
.partitionKey (Attribute .builder ()
40
27
.type (AttributeType .STRING )
41
28
.name ("id" ).build ())
42
29
.billingMode (BillingMode .PAY_PER_REQUEST )
43
30
.build ());
44
31
45
- Function customJava18Function = new Function (this , "LambdaCustomRuntimeJava18" , FunctionProps .builder ()
32
+ var customJava18Function = new Function (this , "LambdaCustomRuntimeJava18" , FunctionProps .builder ()
46
33
.functionName ("custom-runtime-java-18" )
47
34
.handler ("com.amazon.aws.example.ExampleDynamoDbHandler::handleRequest" )
48
35
.runtime (Runtime .PROVIDED_AL2 )
49
- .architecture (Architecture .X86_64 )
50
36
.code (Code .fromAsset ("../runtime.zip" ))
51
37
.memorySize (512 )
52
38
.environment (Map .of ("TABLE_NAME" , exampleTable .getTableName ()))
@@ -56,21 +42,16 @@ public InfrastructureStack(final Construct scope, final String id, final StackPr
56
42
57
43
exampleTable .grantWriteData (customJava18Function );
58
44
59
- HttpApi httpApi = new HttpApi (this , "ExampleApi" , HttpApiProps .builder ()
60
- .apiName ("ExampleApi" )
45
+ var restApi = new RestApi (this , "ExampleApi" , RestApiProps .builder ()
46
+ .restApiName ("ExampleApi" )
61
47
.build ());
62
48
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 ));
71
52
72
53
new CfnOutput (this , "api-endpoint" , CfnOutputProps .builder ()
73
- .value (httpApi . getApiEndpoint ())
54
+ .value (restApi . getUrl ())
74
55
.build ());
75
56
}
76
57
}
0 commit comments