activejdbc 与 aws Lambda
activejdbc with aws Lambda
我无法激活jdbc 使用 aws serverless。
我将我的连接参数添加为 ENV 变量并且 Base.findAll() 有效,但我无法让模型工作,我收到以下错误
"org.javalite.activejdbc.InitException: you are trying to work with models, but no models are found. Maybe you have no models in project, or you did not instrument the models. It is expected that you have a file activejdbc_models.properties on classpath\n\tat org.javalite.activejdb
我检查了我的 jar 文件,它确实有一个 'activejdbc_models.properties' 文件,并且检测似乎有效。
这条路是死胡同吗?我应该直接转向 jdbc 吗?或者我可以让 actveJDBC 与 lambda 一起工作吗?
更新
运行 我的模型之一上的 javap 类 地址,这里是输出
Compiled from "Address.java"
public class com.kwiqhealth.models.Address extends org.javalite.activejdbc.Model {
public com.kwiqhealth.models.Address();
public static org.javalite.activejdbc.MetaModel getMetaModel();
public static org.javalite.activejdbc.MetaModel metaModel();
public static <T extends org.javalite.activejdbc.Model> T findOrCreateIt(java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> T findOrInit(java.lang.Object...);
public static java.util.Set<java.lang.String> attributeNames();
public static java.util.List<org.javalite.activejdbc.associations.Association> associations();
public static int delete(java.lang.String, java.lang.Object...);
public static boolean exists(java.lang.Object);
public static int deleteAll();
public static int update(java.lang.String, java.lang.String, java.lang.Object...);
public static int updateAll(java.lang.String, java.lang.Object...);
protected static org.javalite.validation.NumericValidationBuilder validateNumericalityOf(java.lang.String...);
public static org.javalite.validation.ValidationBuilder addValidator(org.javalite.validation.Validator);
protected static void addScope(java.lang.String, java.lang.String);
public static void removeValidator(org.javalite.validation.Validator);
public static java.util.List<org.javalite.validation.Validator> getValidators(java.lang.Class<? extends org.javalite.activejdbc.Model>);
protected static org.javalite.validation.ValidationBuilder validateRegexpOf(java.lang.String, java.lang.String);
protected static org.javalite.validation.ValidationBuilder validateEmailOf(java.lang.String);
protected static org.javalite.validation.ValidationBuilder validateRange(java.lang.String, java.lang.Number, java.lang.Number);
protected static org.javalite.validation.ValidationBuilder validatePresenceOf(java.lang.String...);
protected static org.javalite.validation.ValidationBuilder validateWith(org.javalite.validation.Validator);
protected static void convertWith(org.javalite.conversion.Converter, java.lang.String...);
protected static void dateFormat(java.lang.String, java.lang.String...);
protected static void dateFormat(java.text.DateFormat, java.lang.String...);
protected static void timestampFormat(java.lang.String, java.lang.String...);
protected static void timestampFormat(java.text.DateFormat, java.lang.String...);
protected static void blankToNull(java.lang.String...);
protected static void zeroToNull(java.lang.String...);
public static boolean belongsTo(java.lang.Class<? extends org.javalite.activejdbc.Model>);
public static void callbackWith(org.javalite.activejdbc.CallbackListener...);
public static <T extends org.javalite.activejdbc.Model> T create(java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> T createIt(java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> T findById(java.lang.Object);
public static <T extends org.javalite.activejdbc.Model> T findByCompositeKeys(java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> org.javalite.activejdbc.LazyList<T> where(java.lang.String, java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> org.javalite.activejdbc.ScopeBuilder<T> scopes(java.lang.String...);
public static <T extends org.javalite.activejdbc.Model> org.javalite.activejdbc.ScopeBuilder<T> scope(java.lang.String);
public static <T extends org.javalite.activejdbc.Model> org.javalite.activejdbc.LazyList<T> find(java.lang.String, java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> T findFirst(java.lang.String, java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> T first(java.lang.String, java.lang.Object...);
public static void findWith(org.javalite.activejdbc.ModelListener, java.lang.String, java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> org.javalite.activejdbc.LazyList<T> findBySQL(java.lang.String, java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> org.javalite.activejdbc.LazyList<T> findAll();
public static java.lang.Long count();
public static java.lang.Long count(java.lang.String, java.lang.Object...);
public static java.lang.String getTableName();
public static boolean isCached();
public static void purgeCache();
}
好的,考虑到您从 javap
命令输出,您的 类 已被检测。但是,您的构建仍然存在一些问题,因为您似乎正在将非检测 类 发布到 AWS Lambda,因此您的例外情况。我在 Lambda 中为 运行 ActiveJDBC 创建了一个非常简单的测试:
@Override
public String handleRequest(Map<String,String> event, Context context) {
context.getLogger().log("Starting to connect...");
Base.open("org.mariadb.jdbc.Driver", "jdbc:mysql://database-1.xxxxx.us-east-2.rds.amazonaws.com/test", "admin", "xcxxxx");
context.getLogger().log("connected!!");
// Base.exec("create database test");
// Base.exec("CREATE TABLE people (id int(11) NOT NULL auto_increment PRIMARY KEY, name VARCHAR(56) NOT NULL, last_name VARCHAR(56), dob DATE, graduation_date DATE, created_at DATETIME, updated_at DATETIME) ENGINE=InnoDB DEFAULT CHARSET=utf8");
context.getLogger().log("Found records in table: " + Base.count("people"));
context.getLogger().log("Found records in table (with model): " + Person.count());
Base.close();
context.getLogger().log("Executed and closed");
return "Lambda done executing..." ;
}
当我执行 Lambda 时,CloudWatch 提供了以下日志:
执行模型后记录的行。
如您所见,JavaLite ActiveJDBC 和 AWS Lambda 之间没有冲突。您需要调查构建问题。
我无法激活jdbc 使用 aws serverless。
我将我的连接参数添加为 ENV 变量并且 Base.findAll() 有效,但我无法让模型工作,我收到以下错误
"org.javalite.activejdbc.InitException: you are trying to work with models, but no models are found. Maybe you have no models in project, or you did not instrument the models. It is expected that you have a file activejdbc_models.properties on classpath\n\tat org.javalite.activejdb
我检查了我的 jar 文件,它确实有一个 'activejdbc_models.properties' 文件,并且检测似乎有效。
这条路是死胡同吗?我应该直接转向 jdbc 吗?或者我可以让 actveJDBC 与 lambda 一起工作吗?
更新 运行 我的模型之一上的 javap 类 地址,这里是输出
Compiled from "Address.java"
public class com.kwiqhealth.models.Address extends org.javalite.activejdbc.Model {
public com.kwiqhealth.models.Address();
public static org.javalite.activejdbc.MetaModel getMetaModel();
public static org.javalite.activejdbc.MetaModel metaModel();
public static <T extends org.javalite.activejdbc.Model> T findOrCreateIt(java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> T findOrInit(java.lang.Object...);
public static java.util.Set<java.lang.String> attributeNames();
public static java.util.List<org.javalite.activejdbc.associations.Association> associations();
public static int delete(java.lang.String, java.lang.Object...);
public static boolean exists(java.lang.Object);
public static int deleteAll();
public static int update(java.lang.String, java.lang.String, java.lang.Object...);
public static int updateAll(java.lang.String, java.lang.Object...);
protected static org.javalite.validation.NumericValidationBuilder validateNumericalityOf(java.lang.String...);
public static org.javalite.validation.ValidationBuilder addValidator(org.javalite.validation.Validator);
protected static void addScope(java.lang.String, java.lang.String);
public static void removeValidator(org.javalite.validation.Validator);
public static java.util.List<org.javalite.validation.Validator> getValidators(java.lang.Class<? extends org.javalite.activejdbc.Model>);
protected static org.javalite.validation.ValidationBuilder validateRegexpOf(java.lang.String, java.lang.String);
protected static org.javalite.validation.ValidationBuilder validateEmailOf(java.lang.String);
protected static org.javalite.validation.ValidationBuilder validateRange(java.lang.String, java.lang.Number, java.lang.Number);
protected static org.javalite.validation.ValidationBuilder validatePresenceOf(java.lang.String...);
protected static org.javalite.validation.ValidationBuilder validateWith(org.javalite.validation.Validator);
protected static void convertWith(org.javalite.conversion.Converter, java.lang.String...);
protected static void dateFormat(java.lang.String, java.lang.String...);
protected static void dateFormat(java.text.DateFormat, java.lang.String...);
protected static void timestampFormat(java.lang.String, java.lang.String...);
protected static void timestampFormat(java.text.DateFormat, java.lang.String...);
protected static void blankToNull(java.lang.String...);
protected static void zeroToNull(java.lang.String...);
public static boolean belongsTo(java.lang.Class<? extends org.javalite.activejdbc.Model>);
public static void callbackWith(org.javalite.activejdbc.CallbackListener...);
public static <T extends org.javalite.activejdbc.Model> T create(java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> T createIt(java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> T findById(java.lang.Object);
public static <T extends org.javalite.activejdbc.Model> T findByCompositeKeys(java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> org.javalite.activejdbc.LazyList<T> where(java.lang.String, java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> org.javalite.activejdbc.ScopeBuilder<T> scopes(java.lang.String...);
public static <T extends org.javalite.activejdbc.Model> org.javalite.activejdbc.ScopeBuilder<T> scope(java.lang.String);
public static <T extends org.javalite.activejdbc.Model> org.javalite.activejdbc.LazyList<T> find(java.lang.String, java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> T findFirst(java.lang.String, java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> T first(java.lang.String, java.lang.Object...);
public static void findWith(org.javalite.activejdbc.ModelListener, java.lang.String, java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> org.javalite.activejdbc.LazyList<T> findBySQL(java.lang.String, java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> org.javalite.activejdbc.LazyList<T> findAll();
public static java.lang.Long count();
public static java.lang.Long count(java.lang.String, java.lang.Object...);
public static java.lang.String getTableName();
public static boolean isCached();
public static void purgeCache();
}
好的,考虑到您从 javap
命令输出,您的 类 已被检测。但是,您的构建仍然存在一些问题,因为您似乎正在将非检测 类 发布到 AWS Lambda,因此您的例外情况。我在 Lambda 中为 运行 ActiveJDBC 创建了一个非常简单的测试:
@Override
public String handleRequest(Map<String,String> event, Context context) {
context.getLogger().log("Starting to connect...");
Base.open("org.mariadb.jdbc.Driver", "jdbc:mysql://database-1.xxxxx.us-east-2.rds.amazonaws.com/test", "admin", "xcxxxx");
context.getLogger().log("connected!!");
// Base.exec("create database test");
// Base.exec("CREATE TABLE people (id int(11) NOT NULL auto_increment PRIMARY KEY, name VARCHAR(56) NOT NULL, last_name VARCHAR(56), dob DATE, graduation_date DATE, created_at DATETIME, updated_at DATETIME) ENGINE=InnoDB DEFAULT CHARSET=utf8");
context.getLogger().log("Found records in table: " + Base.count("people"));
context.getLogger().log("Found records in table (with model): " + Person.count());
Base.close();
context.getLogger().log("Executed and closed");
return "Lambda done executing..." ;
}
当我执行 Lambda 时,CloudWatch 提供了以下日志:
执行模型后记录的行。 如您所见,JavaLite ActiveJDBC 和 AWS Lambda 之间没有冲突。您需要调查构建问题。