Using AWS Cloudformation

Install K2 Agents on EC2 instance using AWS Cloudformation templates.

Prerequisites

  • Register at k2io.net to get customerId, k2 agents release information etc.

  • Go through all the parameters in “Setup Configuration” and update them as per your need.

  • Make sure to have docker included in your EC2 AMI if you are installing Docker version of the K2.

Steps

  • STEP 1: Have your existing EC2 Cloudformation template ready.

    • Steps below will show you how to include K2’s yml in your EC2 CFT

  • STEP 2: Setup Configuration :

    • Update the following parameters from the sample yml below

      • k2IsDocker : Set docker or non docker install of K2 agents, true for docker install and vice versa.

      • k2IsPrivileged : Set privileged mode installation of K2 agents, true for privileged mode and vice versa.

      • k2VersionNumber : Set the K2 agents version for download for e.g. 1.10.10

      • k2CustomerId: Set your K2 customer Id for e.g. 1101

      • k2TempToken : Set the temp token for K2 agents tarball download, You can get it from K2 Manager UI.

    • Copy the sample yml below with updated parameters into your EC2 CFT yml

  • Step 3: Installation of K2 Agents :

    • Add following yml snippet to your EC2 cloudformation provisioning section in the existing template

      • Cloudformation Init Configuration - Here we are adding helper scripts to invoke agent installation during ec2 provision.

      • K2 Agents Installation

      • K2 Demo Vulnerable App Installation

  • Step 4: Once your template is ready and valid, Run it via EC2 console or AWS CLI

  • Step 5: Launch your application with K2

    • Here we are launching a demo app and final cft template is below

Complete Example

Follow some steps and use below template to deploy ec2 instance along with k2 agents

  • Go through all the parameters and define their default values as per your setup or pass them in cloudformation command

  • Provide AMIID in Mappings section as per region, you can only change one region also for your deployment.

  • Save the file as k2linux.yml

  • Run the template

    • Using AWS Console

    • Using AWS Cli For e.g.

      • aws cloudformation create-stack --region ${REGION_NAME} --stack-name ${PROVIDE_STACKNAME_HERE} --template-body file://${PROVIDE_TEMPLATE_NAME}

      • Example Command is below

      • aws cloudformation create-stack --region us-west-1 --stack-name ec2-k2 --template-body file://k2linux.yml

Cloudformation Template :

Setup and Configure parameters in below template as per you environment :

  • StackName: Name of parent stack created where VPC and networking is provisioned, it is needed to define subnet and vpc in which new EC2 instance will be created.

  • KeyName: Name of Key Pair from your region for public private authentication to EC2 instance, Either create a new key pair or use existing ones.

  • AllowedAddress: Define the addresses from where you want to give access to web server ports.

  • InstanceType : Define instance type for your new EC2 instance

  • SSHLocation : Define the addresses from where you want to give SSH access.

  • k2IsDocker : Set docker or non docker install of K2 agents, true for docker install and vice versa.

  • k2IsPrivileged : Set privileged mode installation of K2 agents, true for privileged mode and vice versa.

  • k2VersionNumber : Set the K2 agents version for download for e.g. 1.10.10

  • k2CustomerId: Set your K2 customer Id for e.g. 1101

  • k2TempToken : Set the temp token for K2 agents tarball download, You can get it from K2 Manager UI.

Last updated

Was this helpful?