国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Spring Boot yang digunakan dalam Lambda membuang "statusCode": 502 Gateway tamat masa"
P粉111227898
P粉111227898 2023-08-28 23:12:36
0
1
940
<p>我將 Spring boot jar 文件(它具有 lambda 請求流處理程序)作為 zip 文件上傳到 AWS Lambda。由于 zip 很大,我在 S3 中上傳并在 AWS 控制臺中創(chuàng)建此 Lambda 函數(shù)時給出了該鏈接。正如我到處讀到的那樣,這就是使用簡單方法在 lambda 中部署 Spring Boot 服務(wù)的全部內(nèi)容。我的 Spring Boot 服務(wù)中有 2 個 GET 端點(diǎn)。請在下面找到完整的 Spring boot 服務(wù)代碼和 Lambda 屏幕截圖。</p> <p>錯誤:(出現(xiàn)超時錯誤,因此在 Lambda 測試中增加到 15 分鐘,結(jié)果如下,似乎仍然無法正常工作)</p> <pre class="brush:php;toolbar:false;">Executing function: succeeded (logs ) { &quot;statusCode&quot;: 502, &quot;multiValueHeaders&quot;: { &quot;Content-Type&quot;: [ &quot;application/json&quot; ] }, &quot;body&quot;: &quot;{\&quot;message\&quot;:\&quot;Gateway timeout\&quot;}&quot;, &quot;isBase64Encoded&quot;: false }</pre> <p>Spring boot Lambda 請求流處理程序:(異步,因?yàn)槲矣X得 Lambda 最初需要很長時間才能啟動)</p> <pre class="brush:php;toolbar:false;">public class StreamLambdaHandler implements RequestStreamHandler { private SpringBootLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler; public StreamLambdaHandler() throws ContainerInitializationException { handler = new SpringBootProxyHandlerBuilder() .defaultProxy() .asyncInit() .springBootApplication(SlowApplication.class) .buildAndInitialize(); } @Override public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException { handler.proxyStream(inputStream, outputStream, context); } }</pre> <p>build.gradle(我在此處添加了“task buildZip”以獲取 zip 文件中的 build->“distributions”jar)</p> <pre class="brush:php;toolbar:false;">plugins { id 'java' id 'org.springframework.boot' version '3.1.0' id 'io.spring.dependency-management' version '1.1.0' } group = 'com.example' version = '0.0.1-SNAPSHOT' sourceCompatibility = '17' repositories { mavenCentral() } dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-test' implementation 'mysql:mysql-connector-java:8.0.32' implementation 'org.springframework.boot:spring-boot-starter-jdbc' implementation 'com.amazonaws:aws-lambda-java-core:1.2.2' implementation 'com.amazonaws:aws-lambda-java-events:3.11.1' implementation 'com.amazonaws.serverless:aws-serverless-java-container-spring:1.5.2' } task buildZip(type: Zip) { into('lib') { from(jar) from(configurations.runtimeClasspath) } } tasks.named('test') { useJUnitPlatform() } jar { duplicatesStrategy = DuplicatesStrategy.EXCLUDE manifest { attributes &quot;Main-Class&quot;: &quot;com.example.awstest&quot; } from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } }</pre> <p>Spring Boot應(yīng)用程序類:</p> <pre class="brush:php;toolbar:false;">package com.example.awstest.client; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication @ComponentScan (&quot;com.example.awstest&quot;) public class AWSTestApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(AWSTestApplication.class, args); } }</pre> <p>Spring 啟動控制器:</p> <pre class="brush:php;toolbar:false;">package com.example.awstest.controller; @RestController public class AWSTestController { @Autowired private AWSTestServiceDAO awstestServiceDAO; @CrossOrigin(origins = &quot;*&quot;) @GetMapping(&quot;/searchAllData&quot;) public List<TESTData> searchAllData() { List<TESTData> dataList = awstestServiceDAO.getAllData(); return dataList; } @CrossOrigin(origins = &quot;*&quot;) @GetMapping(&quot;/searchDataByUser/{userno}&quot;) public List<TESTData> searchDataByUser(@PathVariable Integer userno) { List<TESTData> dataList = awstestServiceDAO.findDataByMemberNo(userno); return dataList; } }</pre> <p>Lambda 控制臺:</p> <p>添加處理程序?yàn)椋?lt;code>com.example.awstest.handler.AWSLambdaHandler::handleRequest</code></p> <p>測試功能:apigateway-awsproxy</p> <pre class="brush:php;toolbar:false;">{ &quot;body&quot;: &quot;eyJ0ZXN0IjoiYm9keSJ9&quot;, &quot;resource&quot;: &quot;/{proxy+}&quot;, &quot;path&quot;: &quot;/searchAllData&quot;, &quot;httpMethod&quot;: &quot;GET&quot;, &quot;isBase64Encoded&quot;: true, &quot;pathParameters&quot;: { &quot;proxy&quot;: &quot;/searchAllData&quot; }, &quot;stageVariables&quot;: { &quot;baz&quot;: &quot;qux&quot; }, &quot;headers&quot;: { &quot;Accept&quot;: &quot;text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8&quot;, &quot;Accept-Encoding&quot;: &quot;gzip, deflate, sdch&quot;, &quot;Accept-Language&quot;: &quot;en-US,en;q=0.8&quot;, &quot;Cache-Control&quot;: &quot;max-age=0&quot;, &quot;CloudFront-Forwarded-Proto&quot;: &quot;https&quot;, &quot;CloudFront-Is-Desktop-Viewer&quot;: &quot;true&quot;, &quot;CloudFront-Is-Mobile-Viewer&quot;: &quot;false&quot;, &quot;CloudFront-Is-SmartTV-Viewer&quot;: &quot;false&quot;, &quot;CloudFront-Is-Tablet-Viewer&quot;: &quot;false&quot;, &quot;CloudFront-Viewer-Country&quot;: &quot;US&quot;, &quot;Host&quot;: &quot;1234567890.execute-api.us-east-1.amazonaws.com&quot;, &quot;Upgrade-Insecure-Requests&quot;: &quot;1&quot;, &quot;User-Agent&quot;: &quot;Custom User Agent String&quot;, &quot;Via&quot;: &quot;1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)&quot;, &quot;X-Amz-Cf-Id&quot;: &quot;cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==&quot;, &quot;X-Forwarded-For&quot;: &quot;127.0.0.1, 127.0.0.2&quot;, &quot;X-Forwarded-Port&quot;: &quot;443&quot;, &quot;X-Forwarded-Proto&quot;: &quot;https&quot; }, &quot;multiValueHeaders&quot;: { &quot;Accept&quot;: [ &quot;text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8&quot; ], &quot;Accept-Encoding&quot;: [ &quot;gzip, deflate, sdch&quot; ], &quot;Accept-Language&quot;: [ &quot;en-US,en;q=0.8&quot; ], &quot;Cache-Control&quot;: [ &quot;max-age=0&quot; ], &quot;CloudFront-Forwarded-Proto&quot;: [ &quot;https&quot; ], &quot;CloudFront-Is-Desktop-Viewer&quot;: [ &quot;true&quot; ], &quot;CloudFront-Is-Mobile-Viewer&quot;: [ &quot;false&quot; ], &quot;CloudFront-Is-SmartTV-Viewer&quot;: [ &quot;false&quot; ], &quot;CloudFront-Is-Tablet-Viewer&quot;: [ &quot;false&quot; ], &quot;CloudFront-Viewer-Country&quot;: [ &quot;US&quot; ], &quot;Host&quot;: [ &quot;0123456789.execute-api.us-east-1.amazonaws.com&quot; ], &quot;Upgrade-Insecure-Requests&quot;: [ &quot;1&quot; ], &quot;User-Agent&quot;: [ &quot;Custom User Agent String&quot; ], &quot;Via&quot;: [ &quot;1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)&quot; ], &quot;X-Amz-Cf-Id&quot;: [ &quot;cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==&quot; ], &quot;X-Forwarded-For&quot;: [ &quot;127.0.0.1, 127.0.0.2&quot; ], &quot;X-Forwarded-Port&quot;: [ &quot;443&quot; ], &quot;X-Forwarded-Proto&quot;: [ &quot;https&quot; ] }, &quot;requestContext&quot;: { &quot;accountId&quot;: &quot;123456789012&quot;, &quot;resourceId&quot;: &quot;123456&quot;, &quot;stage&quot;: &quot;prod&quot;, &quot;requestId&quot;: &quot;c6af9ac6-7b61-11e6-9a41-93e8deadbeef&quot;, &quot;requestTime&quot;: &quot;09/Apr/2015:12:34:56 +0000&quot;, &quot;requestTimeEpoch&quot;: 1428582896000, &quot;identity&quot;: { &quot;cognitoIdentityPoolId&quot;: null, &quot;accountId&quot;: null, &quot;cognitoIdentityId&quot;: null, &quot;caller&quot;: null, &quot;accessKey&quot;: null, &quot;sourceIp&quot;: &quot;127.0.0.1&quot;, &quot;cognitoAuthenticationType&quot;: null, &quot;cognitoAuthenticationProvider&quot;: null, &quot;userArn&quot;: null, &quot;userAgent&quot;: &quot;Custom User Agent String&quot;, &quot;user&quot;: null }, &quot;path&quot;: &quot;/prod/searchAllData&quot;, &quot;resourcePath&quot;: &quot;/{proxy+}&quot;, &quot;httpMethod&quot;: &quot;GET&quot;, &quot;apiId&quot;: &quot;1234567890&quot;, &quot;protocol&quot;: &quot;HTTP/1.1&quot; } }</pre> <p>錯誤:</p> <pre class="brush:php;toolbar:false;">s.exceptions.ContainerInitializationException: Could not initialize framework within the 20000ms timeout at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:207) at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:254) at com.example.awstest.handler.AWSLambdaHandler.handleRequest(AWSLambdaHandler.java:36) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) at com.amazonaws.services.lambda.runtime.api.client.EventHandlerLoader$StreamMethodRequestHandler.handleRequest(EventHandlerLoader.java:379) at com.amazonaws.services.lambda.runtime.api.client.EventHandlerLoader$2.call(EventHandlerLoader.java:903) at com.amazonaws.services.lambda.runtime.api.client.AWSLambda.startRuntime(AWSLambda.java:238) at com.amazonaws.services.lambda.runtime.api.client.AWSLambda.startRuntime(AWSLambda.java:190) at com.amazonaws.services.lambda.runtime.api.client.AWSLambda.main(AWSLambda.java:185) 04:36:48.470 [main] ERROR com.amazonaws.serverless.proxy.AwsProxyExceptionHandler -- Called exception handler for: com.amazonaws.serverless.exceptions.ContainerInitializationException: Could not initialize framework within the 20000ms timeout at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:207) at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:254) at com.example.awstest.handler.AWSLambdaHandler.handleRequest(AWSLambdaHandler.java:36) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) at com.amazonaws.services.lambda.runtime.api.client.EventHandlerLoader$StreamMethodRequestHandler.handleRequest(EventHandlerLoader.java:379) at com.amazonaws.services.lambda.runtime.api.client.EventHandlerLoader$2.call(EventHandlerLoader.java:903) at com.amazonaws.services.lambda.runtime.api.client.AWSLambda.startRuntime(AWSLambda.java:238) at com.amazonaws.services.lambda.runtime.api.client.AWSLambda.startRuntime(AWSLambda.java:190) at com.amazonaws.services.lambda.runtime.api.client.AWSLambda.main(AWSLambda.java:185) com.amazonaws.serverless.exceptions.ContainerInitializationException: Could not initialize framework within the 20000ms timeout at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:207) at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:254) at com.example.awstest.handler.AWSLambdaHandler.handleRequest(AWSLambdaHandler.java:36) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) at com.amazonaws.services.lambda.runtime.api.client.EventHandlerLoader$StreamMethodRequestHandler.handleRequest(EventHandlerLoader.java:379) at com.amazonaws.services.lambda.runtime.api.client.EventHandlerLoader$2.call(EventHandlerLoader.java:903) at com.amazonaws.services.lambda.runtime.api.client.AWSLambda.startRuntime(AWSLambda.java:238) at com.amazonaws.services.lambda.runtime.api.client.AWSLambda.startRuntime(AWSLambda.java:190) at com.amazonaws.services.lambda.runtime.api.client.AWSLambda.main(AWSLambda.java:185) END RequestId: 21464e19-8dee-47e0-9acd-5ae04d24431a REPORT RequestId: 21464e19-8dee-47e0-9acd-5ae04d24431a Duration: 20003.03 ms Billed Duration: 20004 ms Memory Size: 512 MB Max Memory Used: 137 MB</pre></p>
P粉111227898
P粉111227898

membalas semua(1)
P粉659518294

Melihat fail Gradle anda, anda menggunakan versi bekas Java Tanpa Pelayan AWS yang sangat lama dan lapuk yang tidak serasi dengan Spring Boot 3.x.

Padam com.amazonaws.serverless:aws-serverless-java-container-spring:1.5.2 并將其替換為 com.amazonaws.serverless:aws-serverless-java-container -springboot3:2.0.0-M1. Anda juga boleh membandingkan di https://github.com/awslabs/aws-serverless-java-container/tree/main/samples/springboot3/pet-store.

Jika anda menghadapi cabaran tamat masa yang sama pada masa hadapan, anda juga boleh mendayakan AWS X-Ray atau OpenTelemetry untuk mengumpul data penjejakan dan melihat di mana masa hilang.

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan