4

我正在使用 STS 4 ( https://spring.io/tools ) 并添加了 Eclipse AWS 工具包 ( https://marketplace.eclipse.org/content/aws-toolkit-eclipse )。

重启 STS 后,我们可以看到一切正常。

在此处输入图像描述

现在我已经在本地安装了 AWS SAM CLI

在此处输入图像描述

并配置了我们有 sam.exe 的路径

在此处输入图像描述

我在本地安装了 Java 8 和 Python 2.7 和 3.6 以及 docker。

现在创建了 AWS Java 无服务器项目 maven install 并尝试运行 sam local

在此处输入图像描述

更新 :

当我尝试运行 SAM-CLI 时,它的工作和返回响应。

在此处输入图像描述

模板.yaml

AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: AWS Lambda Sample Project

Resources:

  Products:
    Type: AWS::Serverless::Function
    Properties:
      Handler: com.example.handler.LambdaHandler
      CodeUri: ./target/lambda-project-1.0-SNAPSHOT.jar
      Runtime: java8
      Timeout: 300
      Environment:
        Variables:
          ENVIRONMENT: "test"
      Events:
        ListProducts:
          Type: Api
          Properties:
            Path: /lambda
            Method: post

并运行配置

在此处输入图像描述

**Maven build :**


[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------------< com.example:lambda-project >---------------------
[INFO] Building lambda-project 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ lambda-project ---
[INFO] Deleting C:\Users\vaqua\Documents\code\AWS-Lambda-Example-master\AWS-Lambda-Example-master\target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ lambda-project ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ lambda-project ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 6 source files to C:\Users\vaqua\Documents\code\AWS-Lambda-Example-master\AWS-Lambda-Example-master\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ lambda-project ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.6.1:testCompile (default-testCompile) @ lambda-project ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\vaqua\Documents\code\AWS-Lambda-Example-master\AWS-Lambda-Example-master\target\test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ lambda-project ---
[INFO] Surefire report directory: C:\Users\vaqua\Documents\code\AWS-Lambda-Example-master\AWS-Lambda-Example-master\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.example.handler.LambdaHandlerTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.291 sec

Results :

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ lambda-project ---
[INFO] Building jar: C:\Users\vaqua\Documents\code\AWS-Lambda-Example-master\AWS-Lambda-Example-master\target\lambda-project-1.0-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-shade-plugin:3.1.0:shade (default) @ lambda-project ---
[INFO] Including com.amazonaws:aws-lambda-java-events:jar:2.0.2 in the shaded jar.
[INFO] Including joda-time:joda-time:jar:2.6 in the shaded jar.
[INFO] Including com.amazonaws:aws-lambda-java-core:jar:1.2.0 in the shaded jar.
[INFO] Including com.typesafe:config:jar:1.3.1 in the shaded jar.
[INFO] Including org.apache.logging.log4j:log4j-api:jar:2.5 in the shaded jar.
[INFO] Including org.apache.logging.log4j:log4j-core:jar:2.5 in the shaded jar.
[INFO] Including com.google.code.gson:gson:jar:2.8.2 in the shaded jar.
[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing C:\Users\vaqua\Documents\code\AWS-Lambda-Example-master\AWS-Lambda-Example-master\target\lambda-project-1.0-SNAPSHOT.jar with C:\Users\vaqua\Documents\code\AWS-Lambda-Example-master\AWS-Lambda-Example-master\target\lambda-project-1.0-SNAPSHOT-shaded.jar
[INFO] Dependency-reduced POM written at: C:\Users\vaqua\Documents\code\AWS-Lambda-Example-master\AWS-Lambda-Example-master\dependency-reduced-pom.xml
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.510 s
[INFO] Finished at: 2018-12-25T21:27:10-06:00
[INFO] ------------------------------------------------------------------------

错误日志:

无法启动 SAM Local。com.amazonaws.eclipse.core.exceptions.AwsActionException

日志:

eclipse.buildId=4.0.2.201811300843-RELEASE
java.version=1.8.0_191
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Framework arguments:  -product org.springframework.boot.ide.branding.sts4
Command-line arguments:  -os win32 -ws win32 -arch x86_64 -product org.springframework.boot.ide.branding.sts4

com.amazonaws.eclipse.lambda
Error
Tue Dec 25 21:21:52 CST 2018
Failed to launch SAM Local.

com.amazonaws.eclipse.core.exceptions.AwsActionException
    at com.amazonaws.eclipse.lambda.launching.SamLocalDelegate.launch(SamLocalDelegate.java:159)
    at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:862)
    at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:720)
    at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1029)
    at org.eclipse.debug.internal.ui.DebugUIPlugin$2.run(DebugUIPlugin.java:1243)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: java.lang.NullPointerException
    at com.amazonaws.eclipse.lambda.launching.SamLocalDelegate.launch(SamLocalDelegate.java:116)
    ... 5 more

eclipse.buildId=4.0.2.201811300843-RELEASE
java.version=1.8.0_191
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Framework arguments:  -product org.springframework.boot.ide.branding.sts4
Command-line arguments:  -os win32 -ws win32 -arch x86_64 -product org.springframework.boot.ide.branding.sts4

org.eclipse.m2e.logback.appender
Warning
Tue Dec 25 21:21:47 CST 2018
Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!

我想知道是否有人解决了这个问题?

4

2 回答 2

2

有同样的问题。

首先你应该打开命令行并运行 where sam 如果你发现路径包含任何空格,例如,如果它的路径中有“程序文件”,那么卸载 samcli 并重新安装它。确保其路径不包含任何空格,例如:C:\Amazon\SAMCLI。当您完成安装 samcli 时,在 cmd 中重新运行之前的代码并复制路径并粘贴到 eclipse 中。

其次,您应该按照 Dimman 的建议创建配置文件。您可以通过运行使用 awscli 来执行此操作 aws configuration

这将自动创建文件。保存并重新启动,一切都应该没问题。

祝你好运。

于 2020-02-17T19:30:23.770 回答
1

有同样的问题,进行了以下更改并能够继续......

在图像中的“并运行配置”部分中。确保您已展开“高级”部分并添加了所需的信息,

  • AWS 配置

  • SAM 本地配置(应该设置)。

还尝试添加执行以下操作。在您的文件夹 C:\Users\YOUR_USER.aws 您应该看到两个文件、凭据和配置。我没有文件配置,所以我创建了它并添加了以下内容:

[default]
region=YOUR_REGION

我还在凭据文件的 [用户名] 下添加了以下行:

region=YOUR_REGION

我保存并重新启动了所有内容并使其正常工作。现在我还有一些其他问题。但它们特定于 JSON 解析。

于 2019-04-27T15:51:37.677 回答