honerlaw / serverless-fargate-plugin

Serverless plugin to deploy fargate tasks to an ECS cluster.
44 stars 16 forks source link

"public" option not working #17

Open eschneider1271 opened 4 years ago

eschneider1271 commented 4 years ago

Hi,

I can't seem to get the public option working. I tried moving this option out of the services array and into the options context, which helped. Now, the generated CloudFormation in my .serverless directory correctly sets AssignPublicIp as desired. However, I'm hitting the following validation error on deployment:

Serverless: [AWS cloudformation 400 0.528s 0 retries] validateTemplate({ TemplateURL:
   'https://.../...-2020-08-05T22:26:46.286Z/compiled-cloudformation-template.json' })

  Error --------------------------------------------------

  Error: The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [slsFargateTestContainerSecurityG] in the Resources block of the template
      at provider.request.catch.error (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/lib/validateTemplate.js:20:13)

It looks like a required security group is not being created?

Here's my full template:

service: slsFargate

provider:
  name: aws
  profile: default
  stage: ${opt:stage, 'test'}
  timeout: 300
  region: us-east-1

plugins:
  - serverless-fargate-plugin

custom:
  fargate:
    - clusterName: Test
      vpc:
        vpcId: vpc-xxx
        subnetIds:
        - subnet-xxx
        - subnet-xxx
        securityGroupIds:
        - sg-xxx
      public: true
      services:
      - name: php-apache-app
        cpu: 512
        memory: 1024
        port: 80
        healthCheckUri: /
        healthCheckInterval: 6
        image: "xxx.dkr.ecr.us-east-1.amazonaws.com/xx:latest"
        autoScale:
          min: 1
          max: 10
          cooldownIn: 30
          cooldownOut: 60
          metric: ECSServiceAverageCPUUtilization
          targetValue: 75
        environment:
          PRODUCTION: false
        protocols:
        - protocol: HTTP

Any ideas? Thanks.

spbarber commented 3 years ago

Hi @eschneider1271,

I ran into the same problem but had to clone the repo and modify the code to get it working correctly.

The following function needed updating in the Cluster class:

public isPublic(): boolean {
    return this.options.services[0].public;
}

Add a public property to the IServiceOptions:

export interface IServiceOptions {
    name: string;
    cpu: number;
    memory: number;
    public: boolean;

I tested it this week and works as it was intended to do so.

gwdp commented 3 years ago

Please, check #26, this issue has been fixed on the active repository since last year.