【问题标题】:AWS - get the current project path while executing code on AWS LambdaAWS - 在 AWS Lambda 上执行代码时获取当前项目路径
【发布时间】:2016-01-26 13:48:15
【问题描述】:

我有一个需求,我需要从当前 java 项目中读取 ini 文件,但我无法动态检索路径。我尝试System.getProperty("user.dir") 来获取路径,但它不起作用。它在本地系统上运行良好,但在 AWS 上不起作用。此代码在AWS Lambda 上运行以处理 S3 上的事件。

【问题讨论】:

    标签: java amazon-web-services aws-lambda


    【解决方案1】:

    尝试读取 LAMBDA_TASK_ROOT 环境变量的值:

    final String projectPath = System.getenv("LAMBDA_TASK_ROOT");
    

    【讨论】:

      【解决方案2】:

      假设你有一个 maven 风格的项目,你应该可以通过在 ./src/main/resources/myfile.ini 中引用它来打开它。

      您也可以通过类路径访问它

      How to really read text file from classpath in Java

      【讨论】:

      • 是的,我想通了。我在资源文件夹下添加了文件并使用 getClass().getClassLoader().getResourceAsStream(xyz.properties) 访问它。如果您明确希望在类路径中包含文件/文件夹,则可以通过将文件/文件夹路径添加为 pom.xml 中的资源来实现。感谢您的输入。 ——
      猜你喜欢
      • 2019-01-28
      • 1970-01-01
      • 2020-05-28
      • 1970-01-01
      • 2020-04-18
      • 2016-12-31
      • 2019-05-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多