4
votes

I am using STS 4 (https://spring.io/tools) and added Eclipse AWS toolkit (https://marketplace.eclipse.org/content/aws-toolkit-eclipse) .

After restart STS we can see everything is good.

enter image description here

Now i have installed AWS SAM CLI local

enter image description here

And configured path where we have sam.exe

enter image description here

I have Java 8 and Python 2.7 and 3.6 and docker installed in my local.

Now created AWS Java serverless project maven install and try to run sam local

enter image description here

Update :

When i am try to run SAM-CLI its working and returning response.

enter image description here

Template.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

And run configuration

enter image description here

**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] ------------------------------------------------------------------------

Error logs:

Failed to launch SAM Local. com.amazonaws.eclipse.core.exceptions.AwsActionException

Logs:

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!

I am wonder if anyone solved that issue ?

2
Were you able to solve this? I am getting exactly same errorcpandey05

2 Answers

2
votes

Had the same issue.

First you should open the command line and run where sam If you find that the path contains any spaces, for example, if it has 'Program Files' in its path then uninstall samcli and reinstall it. Make sure that its path does not contain any spaces, for example: C:\Amazon\SAMCLI. And when you're done installing samcli rerun the previous code in cmd and copy the path and paste in eclipse.

Secondly, you should follow Dimman's advice by creating a config file. You can do so by using awscli by running aws configuration

This will create the file automatically. Save and restart and everything should be fine.

Good luck.

1
votes

Had the same issue, made the following changes and was able to continue...

In your section "And run configuration", in the image. Make sure that you have expanded the "Advanced" section and added the needed info,

  • AWS Configuration

  • SAM Local Configuration (this should be setup).

Also try adding doing the following. In your folder C:\Users\YOUR_USER.aws You should see two files, credentials, and config. I did not have the file config so I created it and added the following:

[default]
region=YOUR_REGION

I also added the following line under the [username] in the credentials file:

region=YOUR_REGION

I saved and restarted everything and got it to work. Now I have some other issues. But they are specific to JSON parsing.