Java 无法将替换解析为AWS Lambda中的值:${akka.stream.materializer}

Java 无法将替换解析为AWS Lambda中的值:${akka.stream.materializer},java,amazon-web-services,akka,aws-lambda,apache-flink,Java,Amazon Web Services,Akka,Aws Lambda,Apache Flink,我有一个java应用程序,其中使用的是flinkAPI。基本上,我试图用代码创建两个数据集,其中记录很少,然后将它们注册为两个表以及必要的字段 DataSet<Company> comp = env.fromElements( new Company("Aux", 1), new Company("Comp2", 2), new Company("Comp3", 3));

我有一个java应用程序,其中使用的是
flinkAPI
。基本上,我试图用代码创建两个数据集,其中记录很少,然后将它们注册为两个表以及必要的字段

 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");
我只是在控制台上打印结果这在我的机器上可以在本地完美运行。我使用带有依赖项的
maven shade插件创建了一个
fat jar
,我正试图在AWS
Lambda
中执行它

因此,当我尝试在那里执行它时,抛出了以下异常(我只发布了前几行):

reference.conf@file:/var/task/reference.conf:804:无法解析 替换为值:${akka.stream.materializer}: com.typesafe.config.ConfigException$UnsolvedSubstitution com.typesafe.config.ConfigException$UnsolvedSubstitution: 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,碰巧看到所有依赖项都在那里。我不知道哪里出了问题


任何帮助都将不胜感激。

您需要在pom->maven shaded plugin->configuration部分添加此代码:

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

reference.conf

最终能够解决这个问题,这是我的pom中的一些主要版本问题。然后我将所有依赖项降级为
flink1.3.2
,并在
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>

maven编译器插件
3.7.0
1.8
1.8
org.apache.maven.plugins
maven阴影插件
3.1.0
包裹
阴凉处
com.ink.FlinkLambdaTest.FlinkToLambda
reference.conf
org.codehaus.plexus.util
org.shade.plexus.util
org.codehaus.plexus.util.xml.Xpp3Dom
org.codehaus.plexus.util.xml.pull*
org.apache.flink
flink-table_2.10
1.3.2
org.apache.flink
弗林克爪哇
1.3.2
org.apache.flink
flink-streaming-java_2.10
1.3.2
org.apache.flink
flink-U 2.10
1.3.2
org.apache.flink
flink-scala_2.10
1.3.2
org.apache.flink
flink-streaming-scala_2.10
1.3.2
确保将主类与您的类一起更改

在渐变中:

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从属关系的项目中:

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
  })

这可能来得有点晚,但下面是关于这个话题的答案

此外,还排除了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>

org.apache.maven.plugins
maven阴影插件
3.0.0
包裹
阴凉处
com.google.code.findbugs:jsr305
org.slf4j:*
log4j:*
*:*
META-INF/*.SF
META-INF/*.DSA
META-INF/*.RSA
my.programs.main.clazz

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

assembly中的assemblyMergeStrategy:={
{
案例路径列表(“META-INF”,xs@_*)=>MergeStrategy.discard
案例“reference.conf”=>MergeStrategy.concat
案例x=>MergeStrategy.first
}
}

我的pom中已经有了这个,没有给我任何运气。无论如何,我会再试一次看看。我想问题是,aws lambda无法运行flink运行.jar,就像我们在本地机器上运行一样。你试过在你的电脑上运行胖jar吗?我还可以建议查看fatJAT,看看reference.conf文件中有什么内容。啊,是的,那么我可以把你和reference.conf联系起来吗?关于这里发生的事情的一些描述如何?结合官方文件和这个答案。工作!对于这个问题,at的答案更有效,但无法解决问题。谢谢你的消息,伙计。
<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>