blog source code

Deploying applications on AWS

There are many ways to deploy AWS applications. On this guide we will talk about S3 and Code Deploy and how we would be able to use both of them to automate your deployment routine.

Before you go further, ensure you have your IAM credentials properly configured on your application and EC2 instances.

Deploy artifacts to AWS S3

You can easily send your project artifact to a S3 bucket. Here are the steps you need to do:

  1. Create a S3 Bucket. On this guide, we will assume you have named your bucket as 'deployment-bucket'.

  2. Create an IAM Policy (or update an already created one) and make sure that grants the following actions:

  1. Copy and paste the following properties on you project definition file (pom.xml).

Notes about S3 plugin:

  • config.plugins.aws.s3.enabled: it turns on the S3 deployment plugin
  • config.plugins.aws.s3.region: is region your bucket is actually placed
  • config.plugins.aws.s3.bucket: the bucket name the plugin should send the artifact

Notes about the Jar plugin:

  • config.plugins.jar.enabled: if true, will generate a runnable jar from your project.
  1. Run 'kikaha deploy' or 'mvn clean deploy' in order to send your just generated artifact to the S3 bucket.

Deploy artifacts through AWS Code Deploy

Although we can easily deploy anything to S3, you probably will notice there is a lot more to do in order to ensure your application is up and running right after you deploy it to an S3 bucket. The best to get it done easily is CodeDeploy. So, lets take a see how we can setup a Kikaha project to deploy applications with CodeDeploy.

  1. Follow the guide above and configure your project to deploy on S3. AWS CodeDeploy can retrieve artifacts from S3 buckets and deploy them on your EC2 instances.

  2. Follow only the two following steps from this AWS CodeDeploy Guide. We will assume you created an Application Deployment named 'microservice1.example.com' and a deployment group named 'production':

  • Configure your instances: it covers how to make your instances ready to receive a deployable artifact and start it once a deployment is ready to be deployed.
  • Creating Your Application and Deployment Groups.
  1. Once you've configured the S3 deployment, include the following properties on your pom.xml file.

Notes about the CodeDeploy plugin:

  • config.plugins.aws.s3.useCodeDeploy: if true, will notify your Application Deployment that a new revision is ready
  • config.plugins.aws.s3.codeDeployApplicationName: the Application Deployment
  • config.plugins.aws.s3.codeDeployDeploymentGroupName: the deployment group you defined for this app
  1. If everything went right, you should be able to run 'kikaha deploy' or 'mvn clean deploy' and see your EC2 instances being automatically updated.