使用 Bitbucket 管道更新 AWS Java Lambda 函数时出错 - java.lang.ClassNotFoundException
Error when update AWS Java Lambda Function using Bitbucket Pipelines - java.lang.ClassNotFoundException
我有一个基本的 AWS Lambda Java 函数 我的函数
public class Hello implements RequestHandler<Request, Response> {
public Response handleRequest(Request request, Context context) {
String greetingString = String.format("Hello %s", request.name);
return new Response(greetingString);
}
}
那个Lambda函数注册在AWS 嗯,controller是com.tds.Hello
并且和AWS相关API Gateway正确。
最终的 JAR 是通过 Maven 构建的,没有问题。当我直接在 AWS 中上传 JAR 时,该功能运行良好。
问题是当我使用 Bitbucket Pipelines in order to do an automatic upload (and update) after committing code, the pipeline runs well with success status following This tutorial (Automating AWS Lambda deployments) 但当我 test/run AWS 中的函数时,我收到以下错误:
{"errorMessage":"Class not found: com.tds.Hello","errorType":"java.lang.ClassNotFoundException"}
有人遇到过这个问题吗?
错误发生在创建 ZIP 文件 并通过 Bitbucket Artifacts 传递时。我避免压缩(ZIP)文件,而是直接使用 JAR 上传到 AWS。我更新 bitbucket-pipelines.yml
如下:
旧bitbucket-pipeline.yml
pipelines:
default:
- step:
name: Build and package
script:
- apt-get update && apt-get install -y zip
- zip my-function.zip target/my-function.jar
- pipe: atlassian/aws-lambda-deploy:0.3.0
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: $AWS_REGION
FUNCTION_NAME: 'my-function'
COMMAND: 'update'
ZIP_FILE: 'my-function.zip'
新建bitbucket-pipeline.yml
pipelines:
default:
- step:
name: Build and package
script:
- pipe: atlassian/aws-lambda-deploy:0.5.0
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: $AWS_REGION
FUNCTION_NAME: 'my-function'
COMMAND: 'update'
ZIP_FILE: 'target/my-function.jar'
我有一个基本的 AWS Lambda Java 函数 我的函数
public class Hello implements RequestHandler<Request, Response> {
public Response handleRequest(Request request, Context context) {
String greetingString = String.format("Hello %s", request.name);
return new Response(greetingString);
}
}
那个Lambda函数注册在AWS 嗯,controller是com.tds.Hello
并且和AWS相关API Gateway正确。
最终的 JAR 是通过 Maven 构建的,没有问题。当我直接在 AWS 中上传 JAR 时,该功能运行良好。
问题是当我使用 Bitbucket Pipelines in order to do an automatic upload (and update) after committing code, the pipeline runs well with success status following This tutorial (Automating AWS Lambda deployments) 但当我 test/run AWS 中的函数时,我收到以下错误:
{"errorMessage":"Class not found: com.tds.Hello","errorType":"java.lang.ClassNotFoundException"}
有人遇到过这个问题吗?
错误发生在创建 ZIP 文件 并通过 Bitbucket Artifacts 传递时。我避免压缩(ZIP)文件,而是直接使用 JAR 上传到 AWS。我更新 bitbucket-pipelines.yml
如下:
旧bitbucket-pipeline.yml
pipelines:
default:
- step:
name: Build and package
script:
- apt-get update && apt-get install -y zip
- zip my-function.zip target/my-function.jar
- pipe: atlassian/aws-lambda-deploy:0.3.0
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: $AWS_REGION
FUNCTION_NAME: 'my-function'
COMMAND: 'update'
ZIP_FILE: 'my-function.zip'
新建bitbucket-pipeline.yml
pipelines:
default:
- step:
name: Build and package
script:
- pipe: atlassian/aws-lambda-deploy:0.5.0
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: $AWS_REGION
FUNCTION_NAME: 'my-function'
COMMAND: 'update'
ZIP_FILE: 'target/my-function.jar'