Skip to content

Create a new stack for your application

This guide is outdated

The guide is outdated due to us moving from PoC to using micro stacks. The new documentation is not ready yet.

If you are setting up something new, please contact team Kjøremiljø first so we can do this together ❤ For more up to date information about how to set up your infrastructure you can take sneak peek at our reference app pirates-iac.

This guide can still be used for trouble shooting purposes for teams that have not yet taken the micro stack structure in use.

This stack will contain the ECS service and task definition for your application, which will run in the ECS cluster we created in the stack above.

Prepare application stack

  1. Go to the root of the environment directory

    # Current directory: "our-repository-iac/dev/infra"
    cd ..
    
  2. Run the ok scaffold command to create a new stack

    # Current directory: "our-repository-iac/dev"
    ok scaffold myapp
    

Add modules to application stack

  1. ECS Service module

    cd myapp/
    # Current directory: "our-repository-iac/dev/myapp"
    ok get-template ecs_service
    
  2. Verify that the module was added

    # Current directory: "our-repository-iac/dev"
    cd myapp/
    ls -la
    
  3. Open ecs_service.tf and replace the values inside the module "ecs_service" block with your own values

Replacing variables

Which values you have to change and what to change them to is explained in the file itself.

Elastic Container Registry

If you plan on using Elastic Container Registry (ECR) for storing container images, fetch the ECR template:

repo-iac/dev/myapp
ok get-template ecr_registry

Open ecr_registry.tf and replace the values marked with a TODO to match your setup.

Apply configuration to set up the application stack

Coffee break

This might take a few minutes to complete.

repo-iac/dev/myapp
terraform init
terraform apply

The application should now be running in the Elastic Container Service (ECS) cluster.

Verify that the service is running

You have two options on how to verify that the application is running:

By checking the URL of the service

  1. The URL of the service is a combination of the service_name and root_domain you specified in the ecs_service module.

    Example: https://myapp.my-team-dev.oslo.systems/

  2. If you are interested in viewing the logs generated by app the application, scroll down to View logs from the service

By checking the ECS console

You can either do this by going to the AWS console and looking at the ECS service:

  1. Go to the AWS console and navigate to the ECS Cluster list
  2. Click on the cluster you created in the infra stack

    The name of the cluster is inherited from the metadata.environment value in the env.yml file.

  3. Click on the Services tab
  4. Click on the service you created in the application stack

    The name of the service is inherited from the variable application_name value in the ecs_service.tf module.

  5. Click on the Tasks tab

    You should see a running task with the status: RUNNING

View logs from the service

  1. Go to the AWS console and navigate to the ECS Cluster list
  2. Click on the cluster you created in the infra stack

    The name of the cluster is inherited from the metadata.environment value in the env.yml file.

  3. Click on the Tasks tab
  4. Click on the task you created in the application stack

    The name of the task is inherited from the variable application_name value in the ecs_service.tf module.

  5. Click on the Logs tab
  6. You will see a list of log streams, the one you want to view is the one with the name of your service, for example myapp

You can verify this by going to the AWS console and looking at the ECS service in the cluster you created in the previous step.