我的应用程序使用的是Spring boot +批处理+ gradle + aws Lambda。我对aws lambda功能不熟悉,当我将jar上载到具有所有读取对象,读取对象权限和写入对象权限的s3存储桶中时。当我测试lambda功能时,得到了fileNotFoundException。有任何建议专家吗?
"cause": {
"errorMessage": "/var/task/org/springframework/cglib/core/NamingPolicy.class (Permission denied)",
"errorType": "java.io.FileNotFoundException",
"stackTrace": [
"java.io.FileInputStream.open0(Native Method)",
"java.io.FileInputStream.open(FileInputStream.java:195)",
"java.io.FileInputStream.<init>(FileInputStream.java:138)",
"sun.misc.URLClassPath$FileLoader$1.getInputStream(URLClassPath.java:1288)",
"sun.misc.Resource.cachedInputStream(Resource.java:77)",
"sun.misc.Resource.getByteBuffer(Resource.java:160)",
"java.net.URLClassLoader.defineClass(URLClassLoader.java:454)",
"java.net.URLClassLoader.access$100(URLClassLoader.java:73)",
"java.net.URLClassLoader$1.run(URLClassLoader.java:368)",
"java.net.URLClassLoader$1.run(URLClassLoader.java:362)",
"java.security.AccessController.doPrivileged(Native Method)",
"java.net.URLClassLoader.findClass(URLClassLoader.java:361)",
"java.lang.ClassLoader.loadClass(ClassLoader.java:424)",
"java.lang.ClassLoader.loadClass(ClassLoader.java:357)",
"org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:394)",
"org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:254)",
"org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:282)",
"org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:126)",
"org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)",
"org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)",
"org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)",
"org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398)",
"org.springframework.boot.SpringApplication.run(SpringApplication.java:330)",
"org.springframework.boot.SpringApplication.run(SpringApplication.java:1258)",
"org.springframework.boot.SpringApplication.run(SpringApplication.java:1246)",
"com.myapp.BatchMain.startApp(BatchMain.java:75)",
"com.myapp.MyHandler.handleRequest(MyHandler.java:12)",
"sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)",
"sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)",
"sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)",
"java.lang.reflect.Method.invoke(Method.java:498)"
]
}
编辑-我的build.gradle
buildscript {
ext {
springBootVersion = '2.0.1.RELEASE'
}
repositories {MavenCentral()}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.5"
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
mainClassName ="com.myapp.MyHandler"
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories { mavenCentral()}
dependencies {
compile 'org.springframework.batch:spring-batch-core:4.0.0.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-batch:2.0.4.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-data-jpa:2.0.4.RELEASE'
compile 'com.microsoft.sqlserver:mssql-jdbc:6.1.0.jre8'
compile 'junit:junit:4.12'
compile 'com.google.code.gson:gson:2.8.2'
compile 'log4j:log4j:1.2.17'
compile 'org.springframework.boot:spring-boot-maven-plugin:2.0.5.RELEASE'
compile 'com.amazonaws:aws-lambda-java-core:1.2.0'
compile 'com.amazonaws:aws-lambda-java-events:2.1.0'
compile 'ch.qos.logback:logback-classic:1.1.2'
}
bootJar {
mainClassName = 'com.myapp.MyHandler'
}
//create a single Jar with all dependencies
task fatJar(type: Jar) {
manifest {
attributes 'Main-Class': 'com.myapp.MyHandler'
}
baseName = 'all-in-one-jar'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
答案 0 :(得分:0)
您可以通过以下命令(Linux操作系统)为/var/task/org/springframework/cglib/core/NamingPolicy.class
提供权限。
chmod +x /var/task/org/springframework/cglib/core/NamingPolicy.class
请参阅:AWS Lambda permission denied when trying to use ffmpeg和https://acloud.guru/forums/aws-lambda/discussion/-KSVv58PhKhA1c6a6EZ-/errormessage-eacces-permission-denied-open-vartaskcsvreadjs?answer=-L5kMj9Q1GfDn7hIv7G8
答案 1 :(得分:0)
通过在build.gradle中添加fileMode = 0755解决了该问题
task fatJar(type: Jar) {
manifest {
attributes 'Main-Class': 'com.myapp.MyHandler'
}
fileMode = 0755
baseName = 'all-in-one-jar'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
with jar
}