Deploying Applications to AWS - Skullabs/kikaha GitHub Wiki
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:
-
Create a S3 Bucket. On this guide, we will assume you have named your bucket as 'deployment-bucket'.
-
Create an IAM Policy (or update an already created one) and make sure that grants the following actions:
"s3:PutObject"
- Copy and paste the following properties on you project definition file (pom.xml).
<config.plugins.aws.s3.enabled>true</config.plugins.aws.s3.enabled>
<config.plugins.aws.s3.region>us-east-1</config.plugins.aws.s3.region>
<config.plugins.aws.s3.bucket>deployment-bucket</config.plugins.aws.s3.bucket>
<config.plugins.jar.enabled>true</config.plugins.jar.enabled>
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.
- 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.
-
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.
-
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.
-
Once you've configured the S3 deployment, include the following properties on your pom.xml file.
<config.plugins.aws.s3.useCodeDeploy>true</config.plugins.aws.s3.useCodeDeploy>
<config.plugins.aws.s3.codeDeployApplicationName>microservice1.example.com</config.plugins.aws.s3.codeDeployApplicationName>
<config.plugins.aws.s3.codeDeployDeploymentGroupName>production</config.plugins.aws.s3.codeDeployDeploymentGroupName>
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
- If everything went right, you should be able to run 'kikaha deploy' or 'mvn clean deploy' and see your EC2 instances being automatically updated.