React and React Native demo applications

Hi, in this entry I would like to share the projects that I’ve developed during the course to create web and mobile applications using React and React Native given by Universidad Politécnica de Valencia (UPV) from Miriada X.

During the course I’ve learn how to use some basic concepts to create the applications with new components and I would like to share here the projects as referece with the GitHub repositories for each one.

react-native-user-search: A mobile application to show how to consume API REST to search users and render the result in a list.

react-native-user-search

Seguir leyendo

AWS, Deploy a serverless application using Lambda and CodePipeline

In this entry I would like to share this example to show how to deploy a serverless application in AWS using lambda, API gateway, S3 and DynamoDB. This example is taken from my last training in AWS cloud. The next diagram shows the architecture:

As you can see there are 3 lambdas connected to DynamoDB serving from API gateway and the frontend is hosted as static web application in a S3 bucket.

Also, it includes a configured development enviroment with a pipeline to automate the releases.

As same as my previous entries, I can’t detail all steps because I had a restricted user. But I’m gonna try to describe all that I consider relevant.

So, let’s get started.

Seguir leyendo

AWS CodeCommit, Adding approval before to merge changes in a branch

Hi in this entry I would like to share my recent learning from my last training in AWS where I had to configure an approval for avoid unwanted chnages in a Productive branch, and also automate it on every new repository.

For this example, the business requirement was «only the users with the role SeniorDevelopers could merge the changes into a branch named Prod«.

In order to solve this, it is needed to create an approval rule in CodeCommit to set the conditions and choose the role that must be allowed to apply changes on the selected branch, then configure Event Bridge to send the event on every new repository cretation to execute a Lambda and associate the rule to that new repository. Something like this:

Let’s get started.

Seguir leyendo

Docker, using bind mounts in a Java project

The bind mounts in a short is way to set a mount point from the host to the container, it means the files are accesible from the file system where the container is launched, for example it could be useful to mount the source code for a web site into the container and do some code changes in the UI and view them inmediatly without build again the Docker image.

Cool right?

Well for Java projects is not so cool, because when the source code is changed it must be compiled and packaged again to be executed or deployed, but the bind mounts could be useful too when there are some external files like configuration properties, input and output files to read, etc. So, if you are working on development environment or in your local machine, perhaps you would have to consider use the bind mounts to get access easily to the files when you are coding or testing new features.

In this entry I’m going to show how to apply in a Maven Java project. All code can be downloaded from my GitHub repository.

Seguir leyendo

Docker basic steps for a Java Project

In this entry I’m going to show how to build a docker image and deploy a Maven Java project from a simple jar file and execute it as micro service.

All code is published into my GitHub repository.

Build an image and run into a container

First, crate a file named Dockerfile at the top of your maven project folder with the next content:

# OS image
FROM alpine:3.14

# Exposed port
EXPOSE 8000

RUN apk --update-cache add openjdk11
WORKDIR /demo
COPY . .
CMD ["java","-jar", "target/demo-1.0-SNAPSHOT.jar", "start"]

This is a very simple configuration file, as you can see the selected image is an alpine linux exposed by the port 8000 and the openjdk11 is installed with the package manager, also I’ve setted a working directory name and all the content is copied from the Maven folder to the image. Finally, the jar is executed with the CMD command.

Seguir leyendo

Visual Studio Code for Java projects

Recently I’ve decided to use the Visual Studio Code (VSC) to develop some Java projects to test the maven support in this tool, in this entry I’m going to share some tips that I’ve noticed.

Requirements

  1. Install Visual Studio Code
  2. Install Extension Pack for Java
  3. Install Java JDK 17 and Java JDK 11

For the last requirement, the JDK could be installed directly from the extension settings in VSC, selecting View > Command Palette (Ctrl+Shift+P) and write into input propmt «Configure Java Runtime«, then select download and install the packages, after that reload the editor. Please note the JDK 17 is a must.

Seguir leyendo

JAX-WS, SOAP web service with Certificate Authentication

There are some examples on internet showing how to configure the certificate authentication for a web service publised with JAX-WS, I’ve seen some of them are using a self-signed certificate or signed by a third party. In this entry I’m going to show how to configure both to publish and consume a simple web service example.

All the code is hosted on my Github repository but I’m going to comment the most relevant here.

First we need to create the certificates, as simple overview, to esatblish the trust contract beetwen client and the server we have to use a valid certificate signed by an Certificate Authority (public or third party) or use a Self Signed Certificate. The first one is the most common use case used by enterprises, the second is a way to test the autentication for development pourposes.

Please, choose one of the next methods:

Method 1: Creating the certificates signed by a private CA

I prefer this method because is similar to production environments. And you can create a dummy CA to simulate this interaction for your development environments.

  1. The service consumer send a Certificate Sign Request to the Certificate Authority (CA)
  2. The CA valid the info and deliver a signed cert
  3. The service provider import the public certificate from CA as a trusted entity
  4. The service consumer send their certificate (signed by the CA) to the service provider to validate their idendity, wich is taken as a trusted (because is signed by the CA), therefore it could trust and allow the access to the client

Use this commands:

Seguir leyendo

AWS, Reset the Windows administrator password on EC2 instance

Is important mention that this method has been tested on AWS with a Windows Server 2022 image, but if you have a previous version you can read some important details from AWS documentation here.

The AWS documentation indicates there are three different ways to reset the password:

But the steps can be different if the instance use some characteristics, for example, the Windows version, the installed agent version, the associated key pair, and some others. So, in this entry I’m going to show how to use the EC2Launch v2 in online and offline method.

Seguir leyendo

Jenkins, Pipeline to create custom input step with timeout

This is an example to show how use the timeout and the input stepts to create a conditional step with determinated timeout. First, the timeout sets the time to wait until the second step complete their tasks, but the second step waits the user input to continue.

The next script waits two days until the user input is received. If no input is received the pipeline is aborted.

pipeline {
   agent any

   stages {
      stage('Hello') {
        steps {
            timeout(time: 2, unit: 'DAYS') { //SECONDS | MINUTES | HOURS | DAYS
                script {
                    def userInput = 
                    input( id: 'input'
                        , message: 'Select options :'
                        , submitter: 'asanchez' // only this user can submit the form, comment to skip
                        , submitterParameter: 'submitterBy' // return the name of the user submitter
                        , parameters: [ 
                            //Params
                            booleanParam(name: 'Check1', defaultValue: false)
                            , [$class: 'TextParameterDefinition', defaultValue: 'Dummy Text', description: 'A simple text param', name: 'textInput'] 
                            , text(defaultValue: 'LOREM', description: '', name: 'textField')
                            , string(defaultValue: 'dummy text', description: '', name: 'inputText', trim: false)
                            , credentials(credentialType: 'com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl', defaultValue: '', description: '', name: 'credentialsParam', required: true)
                            , choice(choices: ['Foo', 'Bar', 'Sed'], description: '', name: 'Options')
                            , password(defaultValue: 'None', description: '', name: 'PasswordField')
                    ])
                    
                    echo("Env: " + userInput)
                    
                }
            
            }
        }
      }
    }
}
Seguir leyendo

AWS EventBridge + SNS, how to send an email when a new EC2 instance is lauched

In this entry I’m going to show how to configure the Amazon EventBridge with the Simple Notification Service to send an email when an EC2 instance is launched (instance creation), either with a Management account, Memeber account into an AWS organization structure, the next diagram shows the structure of this solution.

The official AWS documentation says:

«EventBridge is a serverless service that uses events to connect application components together, making it easier for you to build scalable event-driven applications.

EventBridge receives an event, an indicator of a change in environment, and applies a rule to route the event to a target. Rules match events to targets based on either the structure of the event, called an event pattern, or on a schedule. For example, when an Amazon EC2 instance changes from pending to running, you can have a rule that sends the event to a Lambda function.«

So, our event is the creation of the EC2 instance (when it is launched), we need to create a rule to match that event and redirect to the predefined target, in this case, to the SNS service in order to send the email.

Let’s get started.

Seguir leyendo