1 回答
- 最新
- 投票最多
- 评论最多
0
【以下的回答经过翻译处理】 截至2022年4月4日,CDK-2.19.0版本中似乎没有API GW v2的L2 Builder可用。目前处于alpha状态,可以在https://docs.aws.amazon.com/cdk/api/v2/docs/aws-apigatewayv2-alpha-readme.html中找到参考文档。
下面代码可参考。
<!-- https://mvnrepository.com/artifact/software.amazon.awscdk/apigatewayv2-alpha -->
<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>apigatewayv2-alpha</artifactId>
<version>2.19.0-alpha.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.awscdk/apigatewayv2-integrations-alpha -->
<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>apigatewayv2-integrations-alpha</artifactId>
<version>2.19.0-alpha.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.awscdk/apigatewayv2-authorizers-alpha -->
<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>apigatewayv2-authorizers-alpha</artifactId>
<version>2.19.0-alpha.0</version>
</dependency>
//imports
import software.amazon.awscdk.services.apigatewayv2.alpha.AddRoutesOptions;
import software.amazon.awscdk.services.apigatewayv2.alpha.HttpApi;
import software.amazon.awscdk.services.apigatewayv2.alpha.HttpMethod;
import software.amazon.awscdk.services.apigatewayv2.alpha.HttpStage;
import software.amazon.awscdk.services.apigatewayv2.integrations.alpha.HttpLambdaIntegration;
//code
Function lambdaFunction = Function.Builder.create(this, "LambdaFunction")
.runtime(Runtime.JAVA_11)
.code(Code.fromAsset("software/Test/build/libs/jvmlangs-kotlin-1.0-SNAPSHOT-all.jar"))
.handler("com.aws.blog.jvmlangs.kotlin.MainTest")
.memorySize(1024)
.timeout(Duration.seconds(10))
.logRetention(RetentionDays.ONE_WEEK)
.build();
HttpLambdaIntegration lambdaIntegration = HttpLambdaIntegration.Builder
.create("TestAPI_GW_v2_Integrations", lambdaFunction)
.build();
HttpApi httpApi = HttpApi.Builder
.create(this, "HttpApi")
.build();
httpApi.addRoutes(AddRoutesOptions.builder()
.path("/testBasePath")
.methods(Arrays.asList(HttpMethod.GET))
.integration(lambdaIntegration)
.build());
HttpStage.Builder.create(this, "Stage")
.httpApi(httpApi)
.stageName("dev")
.build();
相关内容
- AWS 官方已更新 1 年前
- AWS 官方已更新 5 个月前
- AWS 官方已更新 2 年前
- AWS 官方已更新 2 年前