.aws/config profile warning

Oct 15, 2018 11:36:31 AM com.amazonaws.auth.profile.internal.BasicProfileConfigLoader loadProfiles
WARNING: Your profile name includes a ‘profile ‘ prefix. This is considered part of the profile name in the Java SDK, so you will need to include this prefix in your profile name when you reference this profile from your Java code.

 

[profile awsdeveloper]
region = us-east-2
output = json

Removed profile bit. Removed Warning.

 

Unable to find a region via the region provider chain. Must provide an explicit region in the builder or setup environment to supply a region

Building Serverless Applications with Spring and AWS -Marc Thomas

Creating an Image Resizing Application

The first time I try to run something, it doesn’t work… surprise, surprise…

Anyway… I look online and it says that all the credentials should have been picked up from when I setup the CLI (Command Line Interface). I checked in Eclipse via Window > Preferences > AWS Toolkit, and it all seemed fine. I did set up a profile of awsdeveloper because I wanted to keep it separate from work aws stuff.

Unable to find a region via the region provider chain. Must provide an explicit region in the builder or setup environment to supply a region. at com.amazonaws.client.builder.AwsClientBuilder.setRegion(AwsClientBuilder.java:436)#

Found the answer in the first stackoverflow question Google found:

“I solved this by adding the AWS_REGION environment variable. E.g. us-east-2. When using Eclipse, you can add this using the Run –> Run Configurations.”

As I was running a JUnit test, I updated the Debug Configuration. 😀

Eureka working :)

http://localhost:8100/currency-converter-feign/from/EUR/to/INR/quantity/2000

{"id":10002,"from":"EUR","to":"INR","conversionMultiple":75.00,"quantity":2000,"totalCalculatedAmount":150000.00,"port":8001}

 

Both services registered with Eureka:

Instances currently registered with Eureka

Application AMIs Availability Zones Status
CURRENCY-CONVERSION-SERVICE n/a (1) (1) UP (1) – gandalf.lan:currency-conversion-service:8100
CURRENCY-EXCHANGE-SERVICE n/a (2) (2) UP (2) – gandalf.lan:currency-exchange-service:8000 , gandalf.lan:currency-exchange-service:8001

 

Finally it all works, but got one error:

2018-10-10 10:15:56.797 ERROR 1524 — [et_localhost-13] c.n.e.cluster.ReplicationTaskProcessor : It seems to be a socket read timeout exception, it will retry later. if it continues to happen and some eureka node occupied all the cpu time, you should set property ‘eureka.server.peer-node-read-timeout-ms’ to a bigger value

Not too worried, going on to Zuul API Gateway now.

Using Feign… errors and success

In the tutorial (Step 21) we need to use Feign. He suggested a pom.xml dependency, but the import didn’t match up.

He was importing:

import org.springframework.cloud.netflix.feign.EnableFeignClients;

and

import org.springframework.cloud.netflix.feign.FeignClient;

But there was nothing in the dependency he advocated. After a bit of searching:

Change:

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
<version>1.4.5.RELEASE</version>
</dependency>

to:

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-core</artifactId>
<version>1.4.5.RELEASE</version>
</dependency>

But this gave all sorts of weird errors, like:

FileNotFoundException: class path resource [org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.class

and:

JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface [util.c:1313]

After removing all the Feign stuff, it was still not right, so I removed the netflix dependency and it was fine.

After a bit of searching I found that  spring-cloud-starter-feign was deprecated and I had to use spring-cloud-starter-openfeign.

A clean, stop and start, and we’re away again, phew! 

Error connecting to http://localhost:8888/limits-service/default with spring.cloud.config.server.git.uri property

I’m following the Microservices tutorial and have come across an error when trying to get properties from my git repository. It’s an easy one, just change the back-slash to forward slashes 🙂

In application.properties:

spring.cloud.config.server.git.uri=file://C:/Users/Me/git/spring-micro-services/git-localconfig-repo

Disabling Spring Boot Security for h2 console

In application.properties:

spring.h2.console.enabled=true
spring.h2.console.path=/h2console/

In my security configuration class I added a bit more to the HttpSecurity configuration:

package com.example.demo;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception{

http.authorizeRequests().antMatchers("/").permitAll().and()
.authorizeRequests().antMatchers("/h2console/**").permitAll();
http.csrf().disable();
http.headers().frameOptions().disable();


}
}

Enabling Spring Boot Security – then disabling it

I added spring-boot-starter-security to my pom, but I’m trying to access the h2-console on localhost and it’s failing because I need to log in.

In my application.xml I have:

spring.security.user.name=user
spring.security.user.password=password

But I don’t want to type this in. How do I disable it? I created a new class in the root of my project and it seemed to work.

package com.example.demo;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception{
http.authorizeRequests().antMatchers("/").permitAll();
}
}

 

 

devtools not working

I used it before, everything was fine, but it seems that in running my application as a Java Project and not a Spring Boot Application from STS, it did not force a restart of the server.

I found this:

https://stackoverflow.com/questions/49386434/live-reload-not-working-in-spring-boot-devtools

“Developer tools are automatically disabled when running a fully packaged application.
If your application is launched from java -jar, you don’t use the spring-boot maven plugin to run your application.”