I have been trying to replicate this aws function example to deploy a lambda with spring cloud function and graalvm.
The function works locally and starts up without a problem.
❯ ./demo
2021-05-10 15:56:17.964 INFO 10764 --- [ main] o.s.nativex.NativeListener
: This application is bootstrapped with code generated with Spring AOT
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.5)
2021-05-10 16:42:42.607 INFO 12792 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication using Java 11.0.11 on loyalty-C02F70R8MD6R with PID 12792 (/Users/user/Workspace/learning/demo/target/demo started by user in /Users/user/Workspace/learning/demo/target)
2021-05-10 16:42:42.607 INFO 12792 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2021-05-10 16:42:42.637 INFO 12792 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
May 10, 2021 4:42:42 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
May 10, 2021 4:42:42 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Tomcat]
May 10, 2021 4:42:42 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet engine: [Apache Tomcat/9.0.45]
May 10, 2021 4:42:42 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring embedded WebApplicationContext
2021-05-10 16:42:42.640 INFO 12792 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 32 ms
2021-05-10 16:42:42.650 INFO 12792 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
May 10, 2021 4:42:42 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
2021-05-10 16:42:42.658 INFO 12792 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-05-10 16:42:42.658 INFO 12792 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 0.071 seconds (JVM running for 0.072)
However, when I deployed it to aws it failed with the following exception
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cloud.function.adapter.aws.CustomRuntimeEventLoop': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.function.adapter.aws.CustomRuntimeEventLoop]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.springframework.cloud.function.adapter.aws.CustomRuntimeEventLoop.<init>()
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1316) ~[na:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1214) ~[na:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564) ~[na:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[na:na]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[na:na]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[na:na]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[na:na]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[na:na]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[na:na]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[na:na]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[na:na]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) ~[na:na]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:782) ~[demo:na]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:774) ~[demo:na]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439) ~[demo:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:339) ~[demo:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1340) ~[demo:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1329) ~[demo:na]
at com.example.demo.DemoApplication.main(DemoApplication.java:10) ~[demo:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.function.adapter.aws.CustomRuntimeEventLoop]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.springframework.cloud.function.adapter.aws.CustomRuntimeEventLoop.<init>()
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:83) ~[na:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1308) ~[na:na]
... 18 common frames omitted
Caused by: java.lang.NoSuchMethodException: org.springframework.cloud.function.adapter.aws.CustomRuntimeEventLoop.<init>()
at java.lang.Class.getConstructor0(DynamicHub.java:3349) ~[na:na]
at java.lang.Class.getDeclaredConstructor(DynamicHub.java:2553) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:78) ~[na:na]
... 19 common frames omitted
I inspected the CustomRuntimeEventLoop and found that class is annotate with
#Configuration
#ConditionalOnProperty("AWS_LAMBDA_RUNTIME_API")
Which means it, only, gets initialised in the AWS environment. And this is why the function did not fail locally. I tried to initialised the class at build time by adding the following snippet to my spring boot application
#NativeHint(initialization = {#InitializationHint(types = {CustomRuntimeEventLoop.class}, initTime = BUILD)})
But this still did not affect the build or runtime behaviour.
Any idea how can I initialise this in the build time?
Have you seem this example - https://github.com/spring-projects-experimental/spring-native/tree/main/samples/cloud-function-aws?
Also, there were issues with that new CustomRuntimeEventLoop that have already been addressed, so consider using the latest snapshot.
Related
I have an ec2 instance running a sample web service on http 8080 port. I am unable to access it from my mac(outside ec2).
I have done the following after going through many stackoverflow questions.
i have deployed my spring boot application on ec2 and is running successfully. I was also able to hit that service from localhost:8080 and got the expected response.
[ec2-user#ip-172-31-34-45 ~]$
[ec2-user#ip-172-31-34-45 ~]$
[ec2-user#ip-172-31-34-45 ~]$
[ec2-user#ip-172-31-34-45 ~]$ cd samplespringboot/
[ec2-user#ip-172-31-34-45 samplespringboot]$ java -jar spring-boot-hello-1.0.jar &
[1] 438
[ec2-user#ip-172-31-34-45 samplespringboot]$
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.6)
2022-12-02 06:59:11.948 INFO 438 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication v1.0 using Java 1.8.0_342 on ip-172-31-34-45.ap-south-1.compute.internal with PID 438 (/home/ec2-user/samplespringboot/spring-boot-hello-1.0.jar started by ec2-user in /home/ec2-user/samplespringboot)
2022-12-02 06:59:11.960 INFO 438 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to 1 default profile: "default"
2022-12-02 06:59:14.739 INFO 438 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-12-02 06:59:14.766 INFO 438 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-12-02 06:59:14.766 INFO 438 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.69]
2022-12-02 06:59:14.931 INFO 438 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-12-02 06:59:14.932 INFO 438 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2825 ms
2022-12-02 06:59:16.405 INFO 438 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-12-02 06:59:16.433 INFO 438 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 5.574 seconds (JVM running for 6.602)
[ec2-user#ip-172-31-34-45 samplespringboot]$
[ec2-user#ip-172-31-34-45 samplespringboot]$
[ec2-user#ip-172-31-34-45 samplespringboot]$ curl localhost:8080
2022-12-02 06:59:41.048 INFO 438 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-12-02 06:59:41.053 INFO 438 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-12-02 06:59:41.055 INFO 438 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms
Hello World!
Hello World, Spring Boot![ec2-user#ip-172-31-34-45 samplespringboot]$
when i try to hit the same from local mac, i am getting connection timed out..
vinays#Vinays-MacBook-Pro target % curl ec2-x-y-z-133.ap-south-1.compute.amazonaws.com:8080
curl: (28) Failed to connect to ec2-x-yz-133.ap-south-1.compute.amazonaws.com port 8080 after 75008 ms: Operation timed out
so i have the following outbound and inbound rules of my ec2 instance
And i have also added NACLs entries like this..
I am not sure what i am doing wrong. Any help is appreciated. Thanks.
[UPDATE]:
I cannot specify port 8080 in edit inbound rules. by default it is 80.
In the inbound rule, you have to add 8080 port as allowed. Otherwise, any host cannot reach to your EC2 node from outside world.
Allow 8080 port from your real IP address would do the trick as well. If you want to enable more secure way, then allow only your real IP for 8080 port, and it will be reachable.
I am running a springboot app in docker using amazon ecs. The problem is the springboot application stops at connecting to datasource.
2022-04-13 01:35:25.473 INFO 1 --- [ main] com.query.QueryServiceApplication : Starting QueryServiceApplication v0.0.1-SNAPSHOT using Java 11.0.14.1 on 0ab5b5efda39 with PID 1 (/query-service.jar started by root in /)
2022-04-13 01:35:25.487 INFO 1 --- [ main] com.query.QueryServiceApplication : No active profile set, falling back to 1 default profile: "default"
2022-04-13 01:35:28.185 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-04-13 01:35:28.231 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 16 ms. Found 0 JPA repository interfaces.
2022-04-13 01:35:30.933 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-04-13 01:35:30.979 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-04-13 01:35:30.980 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.58]
2022-04-13 01:35:31.164 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-04-13 01:35:31.165 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 5477 ms
2022-04-13 01:35:32.967 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
After sometime i get the exception
java.sql.SQLNonTransientConnectionException: Got timeout reading communication packets
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110) ~[mysql-connector-java-8.0.28.jar!/:8.0.28]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.28.jar!/:8.0.28]
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:829) ~[mysql-connector-java-8.0.28.jar!/:8.0.28]
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:449) ~[mysql-connector-java-8.0.28.jar!/:8.0.28]
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:242) ~[mysql-connector-java-8.0.28.jar!/:8.0.28]
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198) ~[mysql-connector-java-8.0.28.jar!/:8.0.28]
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-4.0.3.jar!/:na]
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) ~[HikariCP-4.0.3.jar!/:na]
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-4.0.3.jar!/:na]
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) ~[HikariCP-4.0.3.jar!/:na]
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) ~[HikariCP-4.0.3.jar!/:na]
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-4.0.3.jar!/:na]
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-4.0.3.jar!/:na]
at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:159) ~[spring-jdbc-5.3.16.jar!/:5.3.16]
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:117) ~[spring-jdbc-5.3.16.jar!/:5.3.16]
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80) ~[spring-jdbc-5.3.16.jar!/:5.3.16]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:330) ~[spring-jdbc-5.3.16.jar!/:5.3.16]
at org.springframework.boot.jdbc.EmbeddedDatabaseConnection.isEmbedded(EmbeddedDatabaseConnection.java:162) ~[spring-boot-2.6.4.jar!/:2.6.4]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateDefaultDdlAutoProvider.getDefaultDdlAuto(HibernateDefaultDdlAutoProvider.java:42) ~[spring-boot-autoconfigure-2.6.4.jar!/:2.6.4]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration.lambda$getVendorProperties$1(HibernateJpaConfiguration.java:130) ~[spring-boot-autoconfigure-2.6.4.jar!/:2.6.4]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateSettings.getDdlAuto(HibernateSettings.java:41) ~[spring-boot-autoconfigure-2.6.4.jar!/:2.6.4]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties.determineDdlAuto(HibernateProperties.java:143) ~[spring-boot-autoconfigure-2.6.4.jar!/:2.6.4]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties.getAdditionalProperties(HibernateProperties.java:103) ~[spring-boot-autoconfigure-2.6.4.jar!/:2.6.4]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties.determineHibernateProperties(HibernateProperties.java:95) ~[spring-boot-autoconfigure-2.6.4.jar!/:2.6.4]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration.getVendorProperties(HibernateJpaConfiguration.java:132) ~[spring-boot-autoconfigure-2.6.4.jar!/:2.6.4]
at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.entityManagerFactory(JpaBaseConfiguration.java:132) ~[spring-boot-autoconfigure-2.6.4.jar!/:2.6.4]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.16.jar!/:5.3.16]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.16.jar!/:5.3.16]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638) ~[spring-beans-5.3.16.jar!/:5.3.16]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.16.jar!/:5.3.16]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.16.jar!/:5.3.16]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.16.jar!/:5.3.16]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.16.jar!/:5.3.16]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.16.jar!/:5.3.16]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.16.jar!/:5.3.16]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.16.jar!/:5.3.16]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.16.jar!/:5.3.16]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) ~[spring-context-5.3.16.jar!/:5.3.16]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) ~[spring-context-5.3.16.jar!/:5.3.16]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.16.jar!/:5.3.16]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.4.jar!/:2.6.4]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740) ~[spring-boot-2.6.4.jar!/:2.6.4]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415) ~[spring-boot-2.6.4.jar!/:2.6.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-2.6.4.jar!/:2.6.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) ~[spring-boot-2.6.4.jar!/:2.6.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.4.jar!/:2.6.4]
at com.query.QueryServiceApplication.main(QueryServiceApplication.java:10) ~[classes!/:0.0.1-SNAPSHOT]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[query-service.jar:0.0.1-SNAPSHOT]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[query-service.jar:0.0.1-SNAPSHOT]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[query-service.jar:0.0.1-SNAPSHOT]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) ~[query-service.jar:0.0.1-SNAPSHOT]
I check for security groups as instructed in post link. I made the RDS publicly accessible and allowed access from all IP's and all protocols in the security group. Both my RDS and ECS are in same VPC and same security group. I am not really sure what else to do here ? Will there be an issue connecting since its a docker container ?
I made the RDS publicly accessible
That could actually be a problem. The ECS task may be resolving the RDS endpoint to an Internet IP address, and then trying to connect to the database over the Internet, instead of keeping the traffic inside the VPC. If the ECS task doesn't have a public IP address, or it isn't running in a subnet with a route to a NAT gateway, then it wouldn't be able to connect.
Both my RDS and ECS are in same VPC and same security group.
Being in the same security group does not confer any connectivity by default. This is actually bad practice because it doesn't allow you to restrict traffic on specific ports, since you are mixing different services that use different ports in the same security group. Since you allowed access from all IPs and protocols this shouldn't be the cause of your current issue however.
Some steps to debug this would be to use ECS Exec, or spin up an EC2 instance in the same VPC subnet (with the same security group), and see if the RDS endpoint resolves to an internal or external IP, and see if you can connect with the MySQL command line.
I've created a simple Spring Boot application in IntelliJ and tested the connection with the AWS database, which gives me no error. After creating a mvn clean install, I test the jar in the command-prompt, which also gives me no error. Great, I can upload my JAR file to my AWS Environment. I go to Environment > Configuration > Edit Database, and select my database in the snapshot drop down. But my Environment wound connect to the database. I don't get why it would work. I've been trying to run my app on AWS for days now and I feel I'm close, but don't know how to solve this problem. Plz check out my log:
----------------------------------------
/var/log/web.stdout.log
----------------------------------------
Apr 20 06:15:19 ip-172-31-35-71 web: 2022-04-20 06:15:19.048:INFO::main: Logging initialized #367ms
Apr 20 06:15:19 ip-172-31-35-71 web: 2022-04-20 06:15:19.122:INFO:oejs.Server:main: jetty-9.2.z-SNAPSHOT
Apr 20 06:15:19 ip-172-31-35-71 web: 2022-04-20 06:15:19.201:INFO:oejs.ServerConnector:main: Started ServerConnector#2fcb66eb{HTTP/1.1}{0.0.0.0:5000}
Apr 20 08:34:45 ip-172-31-35-71 web: :: Spring Boot :: (v2.6.6)
Apr 20 08:34:45 ip-172-31-35-71 web: 2022-04-20 08:34:45.466 INFO 11107 --- [ main] c.e.S.SpringBootCrudExampleApplication : Starting SpringBootCrudExampleApplication v0.0.1-SNAPSHOT using Java 11.0.14.1 on ip-172-31-35-71.ec2.internal with PID 11107 (/var/app/current/application.jar started by webapp in /var/app/current)
Apr 20 08:34:45 ip-172-31-35-71 web: 2022-04-20 08:34:45.477 INFO 11107 --- [ main] c.e.S.SpringBootCrudExampleApplication : No active profile set, falling back to 1 default profile: "default"
Apr 20 08:34:47 ip-172-31-35-71 web: 2022-04-20 08:34:47.473 INFO 11107 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
Apr 20 08:34:47 ip-172-31-35-71 web: 2022-04-20 08:34:47.963 INFO 11107 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 472 ms. Found 1 JPA repository interfaces.
Apr 20 08:34:49 ip-172-31-35-71 web: 2022-04-20 08:34:49.554 INFO 11107 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 5000 (http)
Apr 20 08:34:49 ip-172-31-35-71 web: 2022-04-20 08:34:49.582 INFO 11107 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
Apr 20 08:34:49 ip-172-31-35-71 web: 2022-04-20 08:34:49.583 INFO 11107 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.60]
Apr 20 08:34:49 ip-172-31-35-71 web: 2022-04-20 08:34:49.769 INFO 11107 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
Apr 20 08:34:49 ip-172-31-35-71 web: 2022-04-20 08:34:49.769 INFO 11107 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 4143 ms
Apr 20 08:34:50 ip-172-31-35-71 web: 2022-04-20 08:34:50.856 INFO 11107 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
Apr 20 08:34:50 ip-172-31-35-71 web: 2022-04-20 08:34:50.987 INFO 11107 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.7.Final
Apr 20 08:34:51 ip-172-31-35-71 web: 2022-04-20 08:34:51.362 INFO 11107 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
Apr 20 08:34:51 ip-172-31-35-71 web: 2022-04-20 08:34:51.585 INFO 11107 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
Apr 20 08:34:51 ip-172-31-35-71 web: 2022-04-20 08:34:51.957 INFO 11107 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
Apr 20 08:34:51 ip-172-31-35-71 web: 2022-04-20 08:34:51.979 INFO 11107 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
Apr 20 08:34:53 ip-172-31-35-71 web: 2022-04-20 08:34:53.137 INFO 11107 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
Apr 20 08:34:53 ip-172-31-35-71 web: 2022-04-20 08:34:53.148 INFO 11107 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
Apr 20 08:34:54 ip-172-31-35-71 web: 2022-04-20 08:34:54.000 WARN 11107 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
Apr 20 08:34:54 ip-172-31-35-71 web: 2022-04-20 08:34:54.946 INFO 11107 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 5000 (http) with context path ''
Apr 20 08:34:54 ip-172-31-35-71 web: 2022-04-20 08:34:54.965 INFO 11107 --- [ main] c.e.S.SpringBootCrudExampleApplication : Started SpringBootCrudExampleApplication in 11.253 seconds (JVM running for 12.875)
Apr 20 08:36:29 ip-172-31-35-71 web: 2022-04-20 08:36:29.654 INFO 11107 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
Apr 20 08:36:29 ip-172-31-35-71 web: 2022-04-20 08:36:29.658 INFO 11107 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
Apr 20 08:36:29 ip-172-31-35-71 web: 2022-04-20 08:36:29.690 INFO 11107 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
Events
INFO Environment health has transitioned from Warning to Ok.
WARN Environment health has transitioned from Warning to Ok.
INFO The environment was reverted to the previous configuration setting.
INFO Environment health has transitioned from Info to Warning. Configuration update failed 18 seconds ago and took 67 seconds.
The environment was reverted to the previous configuration setting.
Environment health has transitioned from Ok to Info. Configuration update in progress (running for 15 seconds).
ERROR Failed to deploy configuration.
ERROR Creating RDS database failed Reason: DB Instance class db.t2.micro does not support encryption at rest
ERROR Service:AmazonCloudFormation, Message:Stack named 'awseb-e-3a2mk3bca7-stack' aborted operation. Current state: 'UPDATE_ROLLBACK_IN_PROGRESS' Reason: The following resource(s) failed to create: [AWSEBRDSDatabase].
INFO Updating environment Invoice-env's configuration settings.
INFO Environment update is starting.
Unable to connect to Kinesis stream using Spring Cloud Stream Kinesis binder due to error java.lang.IllegalArgumentException: 'dynamoDBClient' must not be null
//Stream binding
EnableBinding(DataStream.class)
public class StreamsConfig {}
//Stream config
public interface DataStream {
String AUDIT_IN = "auditIn";
#Input(AUDIT_IN)
SubscribableChannel auditIn();
}
//Stream Listener
#StreamListener(DataStream.AUDIT_IN)
public void processAudit(finalAuditMessage auditMessage) {
logger.info("Received audit message : {}", auditMessage);
MDCUtil.setContext(auditMessage.getTenantId(), null, null);
persistAuditMessage(auditMessage);
MDCUtil.clearContext();
}
Application.yaml
cloud:
aws:
stack:
auto: false
region:
static: us-west-2
credentials:
useDefaultAwsCredentialsChain: true
management:
context-path: /actuator
security:
enabled: false
roles: ADMIN
endpoint:
metrics:
enabled: true
loggers:
enabled: true
health:
show-details: always
endpoints:
web:
exposure:
include: "health,metrics,info,loggers"
metrics:
export:
statsd:
enabled: true
flavor: telegraf
host: telegraf-s.cluster-services.svc.cluster.local
port: 8125
tags:
service: audit
namespace: {{ .Release.Namespace }}
distribution:
percentiles:
http:
server:
requests: 0.5,0.9,0.99
percentiles-histogram:
http:
server:
requests: true
logging:
level:
org.hibernate.SQL: DEBUG
org.hibernate.type.descriptor.sql.BasicBinder: TRACE
spring:
application:
name: audit
zipkin:
enabled: false
cloud:
stream:
bindings:
auditIn:
content-type: application/json
destination: ***
consumer:
describeStreamRetries: 10
group: ***
kinesis:
binder:
autoCreateStream: true
autoAddShards: false
kplKclEnabled: true
vault:
token: 00000000-0000-0000-0000-000000000000
ssl:
trust-store: ***
trust-store-password: ***
generic:
enabled: false
host: localhost
port: 8200
scheme: https
connection:
timeout: 5000
read-timeout: 15000
authentication: KUBERNETES
kubernetes:
role: owner
kubernetes-path: kubernetes
service-account-token-file: token
kv:
enabled: false
backend: kv-v2
application-name: configuration/mysql
jpa:
open-in-view: false
audit:
filter:
block:
methods: GET
Debug log
INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Detecting the operating system and CPU architecture
[INFO] ------------------------------------------------------------------------
[INFO] os.detected.name: osx
[INFO] os.detected.arch: x86_64
[INFO] os.detected.classifier: osx-x86_64
[INFO]
[INFO] ---------------------------< com.nile:audit >---------------------------
[INFO] Building audit 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:2.2.2.RELEASE:run (default-cli) > test-compile # audit >>>
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) # audit ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # audit ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) # audit ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 5 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # audit ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< spring-boot-maven-plugin:2.2.2.RELEASE:run (default-cli) < test-compile # audit <<<
[INFO]
[INFO]
[INFO] --- spring-boot-maven-plugin:2.2.2.RELEASE:run (default-cli) # audit ---
[INFO] Attaching agents: []
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.2.RELEASE)
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils (file:/Users/arvindkgs/.m2/repository/org/springframework/spring-core/5.2.2.RELEASE/spring-core-5.2.2.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2021-02-24 20:40:38,529 ERROR [main] com.nile.cloudutilities.audit.aspect.MethodMap [] [] - STARTING AUDIT BUILD AT 2021-02-24T15:10:38.524052Z
2021-02-24 20:40:39,984 ERROR [main] com.nile.cloudutilities.audit.aspect.MethodMap [] [] - FINISHED AUDIT BUILD AT 2021-02-24T15:10:39.984543Z: 3/14/0 (0 mappings)
Running custom WebSecurity
2021-02-24 20:40:52,203 DEBUG [main] org.hibernate.SQL [] [] - select loggerconf0_.id as id1_2_, loggerconf0_.create_time as create_t2_2_, loggerconf0_.last_update as last_upd3_2_, loggerconf0_.configuration as configur4_2_, loggerconf0_.service as service5_2_ from logger_configs loggerconf0_ where loggerconf0_.service=?
2021-02-24 20:40:52,219 TRACE [main] org.hibernate.type.descriptor.sql.BasicBinder [] [] - binding parameter [1] as [VARCHAR] - [audit]
2021-02-24 20:40:54,068 ERROR [main] org.springframework.cloud.stream.binding.BindingService [] [] - Failed to create consumer binding; retrying in 30 seconds
org.springframework.cloud.stream.binder.BinderException: Exception thrown while starting consumer:
at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.doBindConsumer(AbstractMessageChannelBinder.java:471) ~[spring-cloud-stream-3.0.1.RELEASE.jar:3.0.1.RELEASE]
at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.doBindConsumer(AbstractMessageChannelBinder.java:90) ~[spring-cloud-stream-3.0.1.RELEASE.jar:3.0.1.RELEASE]
at org.springframework.cloud.stream.binder.AbstractBinder.bindConsumer(AbstractBinder.java:143) ~[spring-cloud-stream-3.0.1.RELEASE.jar:3.0.1.RELEASE]
at org.springframework.cloud.stream.binding.BindingService.doBindConsumer(BindingService.java:169) [spring-cloud-stream-3.0.1.RELEASE.jar:3.0.1.RELEASE]
at org.springframework.cloud.stream.binding.BindingService.bindConsumer(BindingService.java:126) [spring-cloud-stream-3.0.1.RELEASE.jar:3.0.1.RELEASE]
at org.springframework.cloud.stream.binding.AbstractBindableProxyFactory.createAndBindInputs(AbstractBindableProxyFactory.java:112) [spring-cloud-stream-3.0.1.RELEASE.jar:3.0.1.RELEASE]
at org.springframework.cloud.stream.binding.InputBindingLifecycle.doStartWithBindable(InputBindingLifecycle.java:58) [spring-cloud-stream-3.0.1.RELEASE.jar:3.0.1.RELEASE]
at org.springframework.cloud.stream.binding.AbstractBindingLifecycle$$Lambda$1628/000000000000000000.accept(Unknown Source) [spring-cloud-stream-3.0.1.RELEASE.jar:3.0.1.RELEASE]
at java.util.LinkedHashMap$LinkedValues.forEach(LinkedHashMap.java:608) [?:?]
at org.springframework.cloud.stream.binding.AbstractBindingLifecycle.start(AbstractBindingLifecycle.java:57) [spring-cloud-stream-3.0.1.RELEASE.jar:3.0.1.RELEASE]
at org.springframework.cloud.stream.binding.InputBindingLifecycle.start(InputBindingLifecycle.java:34) [spring-cloud-stream-3.0.1.RELEASE.jar:3.0.1.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:182) [spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:53) [spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:360) [spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:158) [spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:122) [spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:894) [spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) [spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at com.nile.audit.AuditService.main(AuditService.java:60) [classes/:?]
Caused by: java.lang.IllegalArgumentException: 'dynamoDBClient' must not be null.
at org.springframework.util.Assert.notNull(Assert.java:198) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.integration.aws.inbound.kinesis.KclMessageDrivenChannelAdapter.<init>(KclMessageDrivenChannelAdapter.java:143) ~[spring-integration-aws-2.3.0.RELEASE.jar:?]
at org.springframework.cloud.stream.binder.kinesis.KinesisMessageChannelBinder.createKclConsumerEndpoint(KinesisMessageChannelBinder.java:314) ~[spring-cloud-stream-binder-kinesis-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.cloud.stream.binder.kinesis.KinesisMessageChannelBinder.createConsumerEndpoint(KinesisMessageChannelBinder.java:291) ~[spring-cloud-stream-binder-kinesis-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.cloud.stream.binder.kinesis.KinesisMessageChannelBinder.createConsumerEndpoint(KinesisMessageChannelBinder.java:89) ~[spring-cloud-stream-binder-kinesis-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.doBindConsumer(AbstractMessageChannelBinder.java:417) ~[spring-cloud-stream-3.0.1.RELEASE.jar:3.0.1.RELEASE]
... 23 more
2021-02-24 20:40:54,167 DEBUG [main] org.hibernate.SQL [] [] - select loggerconf0_.id as id1_2_, loggerconf0_.create_time as create_t2_2_, loggerconf0_.last_update as last_upd3_2_, loggerconf0_.configuration as configur4_2_, loggerconf0_.service as service5_2_ from logger_configs loggerconf0_ where loggerconf0_.service=?
2021-02-24 20:40:54,169 TRACE [main] org.hibernate.type.descriptor.sql.BasicBinder [] [] - binding parameter [1] as [VARCHAR] - [audit]
^C[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 49.955 s
[INFO] Finished at: 2021-02-24T20:40:58+05:30
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "nexus" could not be activated because it does not exist.
pom.xml - https://drive.google.com/file/d/1kBEj6HqTQS5BgA7StaFZBEKfbLrpgSMR/view?usp=sharing
Using following jars
org.springframework.cloud:spring-cloud-stream-binder-kinesis:jar:2.0.0.RELEASE:compile
[INFO] | +- com.amazonaws:amazon-kinesis-client:jar:1.13.0:compile
[INFO] | | +- com.amazonaws:aws-java-sdk-cloudwatch:jar:1.11.655:compile
[INFO] | | \- com.google.protobuf:protobuf-java:jar:2.6.1:compile
[INFO] | +- com.amazonaws:amazon-kinesis-producer:jar:0.14.0:compile
[INFO] | | \- commons-lang:commons-lang:jar:2.6:compile
[INFO] | +- org.springframework.integration:spring-integration-aws:jar:2.3.0.RELEASE:compile
[INFO] | | +- org.springframework.cloud:spring-cloud-aws-core:jar:2.2.0.RELEASE:compile
[INFO] | | | +- com.amazonaws:aws-java-sdk-ec2:jar:1.11.415:compile
[INFO] | | | \- com.amazonaws:aws-java-sdk-cloudformation:jar:1.11.415:compile
[INFO] | | +- org.springframework.cloud:spring-cloud-aws-messaging:jar:2.2.0.RELEASE:runtime
[INFO] | | | +- com.amazonaws:aws-java-sdk-sns:jar:1.11.415:runtime
[INFO] | | | \- com.amazonaws:aws-java-sdk-sqs:jar:1.11.415:runtime
[INFO] | | +- org.springframework.integration:spring-integration-file:jar:5.2.2.RELEASE:runtime
[INFO] | | \- org.springframework.integration:spring-integration-http:jar:5.2.2.RELEASE:runtime
[INFO] | +- org.springframework.cloud:spring-cloud-starter-aws:jar:2.2.0.RELEASE:compile
[INFO] | | +- org.springframework.cloud:spring-cloud-aws-context:jar:2.2.0.RELEASE:compile
[INFO] | | +- org.springframework.cloud:spring-cloud-aws-autoconfigure:jar:2.2.0.RELEASE:compile
[INFO] | | \- javax.activation:javax.activation-api:jar:1.2.0:compile
[INFO] | +- com.amazonaws:aws-java-sdk-dynamodb:jar:1.11.415:compile
[INFO] | | \- com.amazonaws:aws-java-sdk-s3:jar:1.11.415:compile
[INFO] | | \- com.amazonaws:aws-java-sdk-kms:jar:1.11.415:compile
[INFO] | +- com.amazonaws:dynamodb-lock-client:jar:1.1.0:compile
[INFO] | | \- org.apache.httpcomponents:httpcore:jar:4.4.12:compile
[INFO] | +- com.amazonaws:aws-java-sdk-kinesis:jar:1.11.415:compile
[INFO] | \- com.amazonaws:dynamodb-streams-kinesis-adapter:jar:1.5.0:compile
To work with Spring BOOT apps and AWS APIs, try using the official AWS SDK for Java V2 API (as opposed to non Amazon APIs). Amazon recommends moving from V1 to V2.
Here is an example that does use DynamoDB API V2 within a Spring BOOT application. This use case lets a user submit data from a simple web form and then the data is stored in an Amazon DynamoDB table. Then it shows you how to use SNS to fire off a text message. In addition, this shows you how to successfully use AWS Java V2 APIs within a Spring Boot app.
Once its written, this shows you how to deploy the Spring Boot App to the cloud:
Creating your first AWS Java web application
Once you get a basic Spring app working with AWS Java V2 APIs, you can use other services.
My bad. I was creating a DynamoDBClient bean that returned null. This bean is autowired in org.springframework.cloud.stream.binder.kinesis.KinesisMessageChannelBinder.
I built a jar file with JAVA Springboot on my computer and upload it to AWS elastic-beanstalk.
I could run it on my computer but it showed errors when I open the link of beanstalk:
2020/08/26 06:40:20 [error] 3143#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 125.121.75.33, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "xxxxxx-env.eba-4gp64tmr.us-east-1.elasticbeanstalk.com", referrer: "http://xxxxx-env.eba-4gp64tmr.us-east-1.elasticbeanstalk.com/"
However, the web log looks fine:
-------------------------------------
/var/log/web-1.log
-------------------------------------
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.4.BUILD-SNAPSHOT)
2020-08-26 06:39:42.667 INFO 3167 --- [ main] c.b.restservice.RestServiceApplication : Starting RestServiceApplication v0.0.1-SNAPSHOT on ip-171-21-39-87 with PID 3167 (/var/app/current/application.jar started by webapp in /var/app/current)
2020-08-26 06:39:42.678 INFO 3167 --- [ main] c.b.restservice.RestServiceApplication : No active profile set, falling back to default profiles: default
2020-08-26 06:39:46.929 INFO 3167 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-08-26 06:39:46.966 INFO 3167 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-08-26 06:39:46.967 INFO 3167 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.37]
2020-08-26 06:39:47.199 INFO 3167 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-08-26 06:39:47.204 INFO 3167 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 4295 ms
2020-08-26 06:39:49.410 INFO 3167 --- [ main] pertySourcedRequestMappingHandlerMapping : Mapped URL path [/v2/api-docs] onto method [springfox.documentation.swagger2.web.Swagger2Controller#getDocumentation(String, HttpServletRequest)]
2020-08-26 06:39:49.636 INFO 3167 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-08-26 06:39:50.201 INFO 3167 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-08-26 06:39:50.203 INFO 3167 --- [ main] d.s.w.p.DocumentationPluginsBootstrapper : Context refreshed
2020-08-26 06:39:50.252 INFO 3167 --- [ main] d.s.w.p.DocumentationPluginsBootstrapper : Found 1 custom documentation plugin(s)
2020-08-26 06:39:50.349 INFO 3167 --- [ main] s.d.s.w.s.ApiListingReferenceScanner : Scanning for api listing references
2020-08-26 06:39:50.401 INFO 3167 --- [ main] c.b.restservice.RestServiceApplication : Started RestServiceApplication in 9.6 seconds (JVM running for 12.522)
I set the SERVER_PORT to 8080 in Environment properties.
How should I handle this error? If you need any additional information just let me know.
Thank you for #Marcin reminder!
I set SERVER_PORT to 5000 this question has been solved!
Because Elastic Beanstalk will listen to 5000 default.