Thursday, January 18, 2024

Fix AWS Elastic BeansTalk Roles Error

AWS Elastic Beanstalk is a service provided by Amazon Cloud in order to deploy and manage web application in a simple way. This post focus on an error that you can get when you try to create for the first time a beanstalk application and environment (dev, staging, production.


AWS Elastic Beanstalk


When working with Elastic Beanstalk, it's possible to have this error "aws-elasticbeanstalk-ec2-role doesn't exists when creating the environment". This is due to the fact that Amazon is no more creating the role and it should be manually added.

When creating an environment to run the application on EC2 instances, 2 roles are required. 

aws-elasticbeanstalk-service-role:

- AWSElasticBeanstalkManagedUpdatesCustomerRolePolicy 

- AWSElasticBeanstalkEnhancedHealth

aws-elasticbeanstalk-ec2-role:

- AWSElasticBeanstalkWebTier 

- AWSElasticBeanstalkWorkerTier

- AWSElasticBeanstalkMulticontainerDocker


so in order to fix the errors "No Environment found for EnvironmentName" and "aws-elasticbeanstalk-ec2-role doesn't exists when creating the environment", you should add the new rol in the IAM roles. To do so:

    - Open IAM console

    - Choose Roles and create a new Role

    - Choose "AWS Service" as  a trusted entity

    - For the use Case, use EC2

    - Attach AWSElasticBeanstalkWebTier, AWSElasticBeanstalkWorkerTier, and AWSElasticBeanstalkMulticontainerDocker.

    - Last, don't forget to create the Environment using the already created role for EC2.


AWS Beanstalk Role

Monday, January 18, 2021

How to succeed your Interview at Amazon

Assalamou Alaykom Everybody, and welcome back to Me. Yes I am actually back to the Dev and I will be sharing with you some tips as usual. Hope you keep always your positivity as you need it everywhere.


So, you may want to find a job at Amazon, which I think is an amazing company to work in. Just by reading their leadership pillars, you can understand easily how wonderful to work with such people.



It was my case. So i will share with you some tips to know before looking for a job at Amazon or google.

My first advice is to get prepared for the interviews before even applying. In fact, I have learnt just to get the required time to get ready before starting to search for new job. It may be even 1 year before begining. Oh yes that was surprising for me but I understood that to get really ready, you may require all this time.  

So the first move is to well prepare your CV, it should be attractive and concise. Well this is so hard to achieve especially for me, but I got a good advice from a recruiter who told me : "Short resume gives us the curiousity to know more about you". That day, I absolutely understand that I need to learn how to commercialize my resume and introduce some curiousity in the mind of the recruiter, who finally don't know me and receives handred of application daily. 

Think about that and add some positivity and special things in your Resume in order to make it more attractive. As i like design, I have decided to make a little bit of colors, a touch of joy as I don't like black resume. And trust me it works because you get out from the fleet with a special signature. So try to add your own signature that shows something of your personality and may. 

Now that the resume is ready, you need to prepare yourself to tell a story about your old jobs. Not a boring story, but a good ones:

  •  What was your contribution and the result with tangible data if possible
  • The challenges and Mistakes or failures
  • What you would do better 
  • Did you get any conflicts
  • How you manage deadlines and problems
In fact, it's true that during the interviews we talk just superficially. We don't try to show exactly what we have faced during our projects, to talk frankly about some bad experiences. But I have learnt that we should come back to those experiences and describe what was successful and a distaster. 
At the end don't forget that we are presenting ourself as a human being not just a bench of technologies. I advice you also to have a look on Emotional Intelligence which is very important as part of your culture and personality. In fact you may have an extarordinary technical background, but the fact that you lack some intelligence in deeling with people may cause disasters. To be more successful, you need to learn how to share knowledges, encourage people around you and motivate them. So don't forget to show that also.

Now coming back to some tips with Amazon interview. The first one is a technical and small behavior test. And trust me, it is not easy to succeed it even if you are a senior software engineer. Yes, indeed, those tests require some knowlege about algorithms that we don't use in our daily tasks.
You may say what't the need of such tests. It was my first thought, but when I had a look on those tests, it was just amazing how lovely and challenging they are. I may stay nights without sleeping thinking about a tricky solution. 

So, as you are looking for Amazon position and preparing for an interview, try first to get ready with those nice problems and solve many of them before applying. One of the best website to get ready is leetcode.com. It's just gorgious not only because you write your solution but also you can compare it with other solutions in terms of performances and that's an amazing thing.

You can create an account on  leetcode.com and start with easy, medium then hard problems. It will give you a good chance to integrate Amazon or Google by getting trained and explaining your solution, performances and used strategy.

Another resource that you can use is a very good book named "Cracking the Coding Interview 189 Programming Questions and Solutions". It gives good details and strategies about how to get ready for interviews with big companies like Amazon, Apple, and Google. You can fin it online and take somtime reading it but it's worthy.

That's my advices for today. Hope for you the best and share with me your tips, i would like to hear from you. 

Enjoy the Day.




Sunday, November 30, 2014

Java Interview Questions

Here few questions that can be asked in job interviews about Java.

Java interview question for experts


Actual Java Version:

Java 21 has arrived in a production release with 15 features including virtual threads, a generational Z garbage collector, and a key encapsulation mechanism API.


Explain Encapsulation:

Encapsulation in java is the process of wrapping code and data inside a single unit, and make this unit accessible or not. This helps to protect the code and give access to use it only through getters and setters that give limits to change variables and data.


Encapsulation access modifiers

In Java, the terms "public," "protected," and "private" provide varied degrees of visibility and encapsulation. In Java:

  • "public" makes a member accessible from any class, 
  • "protected" permits access inside the same package and by subclasses,
  • "private" restricts access to only within the declaring class
  • the default "package-private" gives access only within the package

Abstract class

An abstract class is that which can have one or more than one abstract methods. Abstract class is used to provide abstraction by hiding implementation and leave it on its child class.

  •  Abstract methods are those which don't have implementation/body rather only has its declaration. 
  • it necessarily have abstract keyword.
  • we can't instantiate our abstract class.
  • all variables inside abstract class must be static.

Explain Static in java:

static is a keyword which makes any variable or method a class level variable or class level method ,means we can access it by our class name without making object of class (without instantiating the class).

Collections in java:

List interface: List interface extends the Collection interface, and it is an ordered collection of objects. It contains duplicate elements.

Set interface: Set (java.util.Set) interface is a collection which cannot contain duplicate elements.

Queue interface: Queue (java.util.Queue) interface defines queue data structure, which stores the elements in the form FIFO

Dequeue interface: it is a double-ended-queue

Map interface: A Map (java.util.Map) represents a key, value pair storage of elements. Map interface does not implement the Collection interface


Collections in java


Lambda in java

Lambda expressions are a concise way to represent anonymous functions. They provide implementation of functional interface. Lambda expression allow hence to pass a function as argument and return values from methods.


lambda expressions are a concise way to represent anonymous functions. They allow us to pass functions as arguments to methods and return them as values from methods. An interface which has only one abstract method is called functional interface. Java provides an annotation @FunctionalInterface, which is used to declare an interface as functional interface.

  1. (argument-list) -> {body}


Java functional interface: annotation @FunctionalInterface

A functional interface contains only a single abstract method which is not implemented. It can contains default and static method that have implementation

Functional interfaces are significant because they are the only types that can serve as the context for a lambda expression or method reference in Java 8. Java provide an annotation for them; @functionalInterface.

Here some example of Default functional interfaces in java

java lambda and function interface


Example of function interface:

  • consumer: A Consumer is a functional interface that accepts a single input and returns no output. (biconsumer)
  • supplier: This Functional Interface is used in all contexts where there is no input but an output is expected.
  • function: represents function which take arguments and return result. unaryoperator extend function but the input and oytput is the same type. (unaryOperator work on 1 operator, binaryoperator)
  • predicate: used for conditionel check. represents a boolean value function. Can be used with filter() operator (specialized predicate, intpredicate, longpredicate..)


Streams in java

Streams are wrappers around a data source, allowing us to operate with that data source and making bulk processing convenient and fast.

A stream does not store data and, in that sense, is not a data structure. It also never modifies the underlying data source.

A terminal operation means that once the operation is performed, the stream pipeline is considered consumed and can no longer be used

Intermediate operations such as filter() return a new stream on which further processing can be done. Terminal operations, such as forEach(), mark the stream as consumed, after which point it can no longer be used further.

Tuesday, November 25, 2014

Configure Maven to Deploy on Nexus

Today we will give the tip to deploy your war on Nexus.



So, in order to be able to deploy you war on a remote Repository using Maven, you need to add some configuration to your pom.xml. Here the lines to add :


<distributionManagement>
 <repository>
  <id>releases</id>
  <name>Releases</name>
  <url>http://NEXUS_ADDRESS:8081/nexus/content/repositories/releases/</url>
 </repository>
 <snapshotRepository>
  <id>snapshots</id>
  <name>Snapshots</name>
  <url>http://NEXUS_ADDRESS:8081/nexus/content/repositories/snapshots/</url>
 </snapshotRepository>
</distributionManagement>

You need to make sure that you have the right to deploy on the repository otherwise you may have an error like this :

 Access denied to http://NEXUS_ADDRESS:8081/nexus/content/repositories/snapshots/my_project/my_project/0.0.1-SNAPSHOT/my_projectm2m-0.0.1-20141125.092913-1.war. Error code 401, Unauthorized -> [Help 1]

So if you have access to the server using login/Password, you can provide that information in the .m2/setting.xml file :




<server>
    <id>all</id>
    <username>user</username>
    <password>password</password>
</server>

If you like the post, and it helps you, don't forget to share 

Tuesday, November 4, 2014

JBoss 7 : Set JAVA_OPTS in JBoss standalone.sh

I was working with a JBoss EAP 6 server (based on JBoss As7). This latest is installed on Linux server.

As the allocated memory is not enough, I wanted to add more space. To do so, you think first of modifying the JAVA_OPTS in standalone.sh. But this will not be taken in account.

The solution is in fact to change these JAVA_OPTS parameters in standalone.conf located in jboss-eap-6.2/bin/.


Don't forget to share ...  

Monday, November 3, 2014

Set Authentication WebService and Set Authentication Cookies in SoapUi

After development step, we need to test the Web Services. Using SoapUi, we can give the generated WSDL address and get all the exposed WebMethods.

I developed an application where authentication is needed. So the called method is authenticate which will generate a JSessionId (Cookie) :


@Resource 
private WebServiceContext wsContext;

 
@WebMethod
public User authenticate(@WebParam(name = "userName") String userName, @WebParam(name = "password") String password){
   
 User userToconnect = null;

 HttpServletRequest req = (HttpServletRequest) wsContext.getMessageContext().get(MessageContext.SERVLET_REQUEST);

 userToconnect = webService.authenticate(userName, password);
  
 req.getSession().setAttribute("User", userToconnect);
    
 return userToconnect;  
}

In next method, we will need to get the user. This one will no more be sent by the authenticated user, but it will be retrieved directly from the WebServiceContext.


public User getUser(WebServiceContext wsContext) throws Exception{

 User user = getUserFromSession(wsContext);
 if(user== null){
  throw new  Exception("User not Authenticated ", UamErrorCode.INVALID_PARAMETER);
 }
 return user.getEnterpriseName();
}


Calling the authenticate method using SoapUi, we will get a Set-Cookie in the header.



Then, in next call, user need to specify the given JsessionId. So the Authentication Cookies should be specified in SoapUi for next requests. This can be done using headers. Clic on add, Copy the JSeesionId generated by the autehnticate (copy all the row, paste, then remove the Set-Cookie). Then create a Header called Cookie, and Set the JSESSIONID.



Thant's all, now your method will work.

Don't forget to share with friends ...

Articles les plus consultés