Skip to content

New APIs to get service deployment info 🚪 #1069

@iamhopaul123

Description

@iamhopaul123

Problem Overview

Copilot has been in an active development stage for a while. As we have more features and new commands added to our CLI, one issue starts getting painful which is the fact that we don’t have APIs that returns info about the deploy relationship between environments and services.

For example, svc show first witnessed this problem and we took the short path strategically by simply checking if we can get stackNotExistsErr, instead of creating a more reusable method to determine if a service is deployed or not. This results in the issue that svc show fails when the service deployment stack is creating. Also, svc logs/status and env show/status suffered from the same problem and they use different ways of determining if a service is considered deployed or not.

Then the real ghost of the tech debt continued haunting us when we found our svc delete --env fails to work properly. Users cannot delete their service from a specific environment. To fix this bug, we’ll need to be able to determine if it is the last environment that the service is deleted from. If so, then we need to empty the ECR repo otherwise app delete will fail because the ECR repo is not cleaned yet. Also it doesn’t make sense to leave it non-empty when there’s no service in the app.

Thus, I think it would be helpful to have more APIs available so that we can easily list all environments a service is deployed in, all services that deployed in the environment, and if a service is deployed in an environment or not.

Specification

ListDeployedServices(appName string, envName string) ([]*Service, error)
ListDeployedServices returns all the deployed service in a specific environment of an application.

env show can use it to list all the services deployed in that environment.

ListEnvironmentsDeployedTo(appName string, svcName string) ([]*Environment, error)
ListEnvironmentsDeployedTo returns all the environment that a service is deployed in.

svc status/logs can use it to list all environments that the service is deployed in to facilitate Ask(). svc show uses this method to loop through only environments with the service deployed in when describing the service. svc delete uses this to determine if it is the last environment to delete the service from, so that it can clean the ECR repo.

IsDeployed(appName string, envName string, svcName string) (bool, error)
IsDeployed returns whether a service is deployed in an environment or not.

svc status/logs can use it to validate the values passed in by flags for svc and env name.

Implementation Plan

Under the hood we use GetResourcesByTags() in the three methods above to get the ECS service ARN. A couple of things to fix:

  • Add those three APIs to deploy pkg
    Fix commands that include service deployment relationship
  • svc show
  • svc logs
  • svc status
  • env show

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/designIssues that are design proposals.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions