无法将替换解析为值:AWS Lambda

时间:2018-02-21 11:35:25

标签: java amazon-web-services akka aws-lambda apache-flink

我有一个java应用程序,我正在使用Flink Api。所以基本上我要对代码做的是创建两个记录很少的数据集,然后将它们作为两个表和必要的字段注册。

 DataSet<Company> comp = env.fromElements(
                new Company("Aux", 1),
                new Company("Comp2", 2),
                new Company("Comp3", 3));

        DataSet<Employee> emp = env.fromElements(
                new Employee("Kula", 1),
                new Employee("Ish", 1),
                new Employee("Kula", 3));


        tEnv.registerDataSet("Employee", emp, "name, empId");
        tEnv.registerDataSet("Company", comp, "cName, empId");

然后我尝试使用Table API

加入这两个表
Table anotherJoin = tEnv.sql("SELECT Employee.name, Employee.empId, Company.cName FROM " +
                "Employee RIGHT JOIN Company on Employee.empId = Company.empId");

我只是在控制台上打印结果。 在我的计算机上完全可以在本地。我使用带有依赖关系的fat-jar创建了maven-shade-plugin,我正在尝试在AWS Lambda中执行它。

所以当我尝试在那里执行时,我会被抛出以下异常(我只发布前几行):

  

reference.conf @ file:/var/task/reference.conf:804:无法解析   替换为值:$ {akka.stream.materializer}:   com.typesafe.config.ConfigException $ UnresolvedSubstitution   com.typesafe.config.ConfigException $ UnresolvedSubstitution:   reference.conf @ file:/var/task/reference.conf:804:无法解析   替换为值:$ {akka.stream.materializer} at   com.typesafe.config.impl.ConfigReference.resolveSubstitutions(ConfigReference.java:111)   在   com.typesafe.config.impl.ResolveContext.realResolve(ResolveContext.java:179)   在   com.typesafe.config.impl.ResolveContext.resolve(ResolveContext.java:142)

我在Lambda中执行它之前解压缩了jar,并碰巧看到所有的依赖项都在那里。我无法弄清楚哪里出错了?

任何帮助都可以得到赞赏。

5 个答案:

答案 0 :(得分:12)

您需要在pom中添加此代码 - &gt; maven-shaded-plugin - &gt;配置部分:

<transformers>
    <!-- append default configs -->
    <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
        <resource>reference.conf</resource>
    </transformer>
</transformers>

答案 1 :(得分:2)

能够最终解决这个问题,这是我的pom中的一些主要版本问题。然后,我将所有依赖项降级为Flink 1.3.2,并在<relocations>插件中添加了shade。它现在有效。我正在附上整个pom,所以有一天它会帮助某人:

<build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.7.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>


       <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <mainClass>com.ink.FlinkLambdaTest.FlinkToLambda</mainClass>
                </transformer>
                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                  <resource>reference.conf</resource>
                </transformer>
              </transformers>
              <relocations>
                <relocation>
                  <pattern>org.codehaus.plexus.util</pattern>
                  <shadedPattern>org.shaded.plexus.util</shadedPattern>
                  <excludes>
                    <exclude>org.codehaus.plexus.util.xml.Xpp3Dom</exclude>
                    <exclude>org.codehaus.plexus.util.xml.pull.*</exclude>
                  </excludes>
                </relocation>
              </relocations>
            </configuration>
          </execution>
        </executions>
      </plugin>  
    </plugins>
  </build>

<dependencies>
    <dependency>
      <groupId>org.apache.flink</groupId>
      <artifactId>flink-table_2.10</artifactId>
      <version>1.3.2</version>
    </dependency>

    <dependency>
      <groupId>org.apache.flink</groupId>
      <artifactId>flink-java</artifactId>
      <version>1.3.2</version>
    </dependency>
    <dependency>
      <groupId>org.apache.flink</groupId>
      <artifactId>flink-streaming-java_2.10</artifactId>
      <version>1.3.2</version>
    </dependency>
    <dependency>
      <groupId>org.apache.flink</groupId>
      <artifactId>flink-clients_2.10</artifactId>
      <version>1.3.2</version>
    </dependency>

    <dependency>
      <groupId>org.apache.flink</groupId>
      <artifactId>flink-scala_2.10</artifactId>
      <version>1.3.2</version>
    </dependency>

    <dependency>
      <groupId>org.apache.flink</groupId>
      <artifactId>flink-streaming-scala_2.10</artifactId>
      <version>1.3.2</version>
    </dependency>

    </dependencies>

确保使用您的主类更改

答案 2 :(得分:0)

在gradle中:

buildscript {
    repositories {
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }
    dependencies {
        classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
    }
}
apply plugin: 'com.github.johnrengelman.shadow'

然后,在聚合akka dependcies的项目中:

shadowJar {
    include 'reference.conf'
}

有了这个,你应该能够正常构建(例如通过调用汇编和构建任务)。

Intellij IDEA也支持这一点。 FTW!它还支持下面的SBT结构。

lazy val assemblySettings = Seq(
  assemblyJarName in assembly := name.value + ".jar",
  assemblyMergeStrategy in assembly := {
    case PathList("META-INF", xs @ _*) => MergeStrategy.discard
    case _ => MergeStrategy.first
  })

答案 3 :(得分:0)

这可能会晚一点,但这是flink website对此主题的回答。

还将排除有关META-INF文件夹的信息,这可能会在使用jar时引起安全问题。

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <artifactSet>
                            <excludes>
                                <exclude>com.google.code.findbugs:jsr305</exclude>
                                <exclude>org.slf4j:*</exclude>
                                <exclude>log4j:*</exclude>
                            </excludes>
                        </artifactSet>
                        <filters>
                            <filter>
                                <!-- Do not copy the signatures in the META-INF folder.
                                Otherwise, this might cause SecurityExceptions when using the JAR. -->
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>my.programs.main.clazz</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

答案 4 :(得分:0)

对于SBT用户,这对我有用。

assemblyMergeStrategy in assembly := {
  {
    case PathList("META-INF", xs@_*) => MergeStrategy.discard
    case "reference.conf" => MergeStrategy.concat
    case x => MergeStrategy.first
  }
}