svdgraaf / serverless-fargate-tasks

Run Fargate tasks within your serverless project
43 stars 21 forks source link

ECS Service stuck on creation #11

Open Julian-Belcastro opened 3 years ago

Julian-Belcastro commented 3 years ago

Hi!

Trying to deploy a CloudFormation template via Serverless gets stuck with 'AWS::ECS::Service' stuck on 'CREATE_IN_PROGRESS' with status 'Resource creation Initiated'.

Thank you!

CloudFormation Template

"FargateTasksCluster": {
            "Type": "AWS::ECS::Cluster"
        },
        "FargateTasksLogGroup": {
            "Type": "AWS::Logs::LogGroup"
        },
        "MytaskTask": {
            "Type": "AWS::ECS::TaskDefinition",
            "Properties": {
                "ContainerDefinitions": [{
                    "Name": "my-task",
                    "Image": "mountainpass/infrastructure:helloworld",
                    "Environment": [],
                    "LogConfiguration": {
                        "LogDriver": "awslogs",
                        "Options": {
                            "awslogs-region": {
                                "Fn::Sub": "${AWS::Region}"
                            },
                            "awslogs-group": {
                                "Fn::Sub": "${FargateTasksLogGroup}"
                            },
                            "awslogs-stream-prefix": "fargate"
                        }
                    }
                }],
                "Family": "my-task",
                "NetworkMode": "awsvpc",
                "ExecutionRoleArn": {
                    "Fn::Sub": "arn:aws:iam::${AWS::AccountId}:role/ecsTaskExecutionRole"
                },
                "TaskRoleArn": {
                    "Fn::Sub": "${IamRoleLambdaExecution}"
                },
                "RequiresCompatibilities": ["FARGATE"],
                "Memory": "0.5GB",
                "Cpu": 256
            }
        },
        "MytaskService": {
            "Type": "AWS::ECS::Service",
            "Properties": {
                "Cluster": {
                    "Fn::Sub": "${FargateTasksCluster}"
                },
                "LaunchType": "FARGATE",
                "ServiceName": "my-task",
                "DesiredCount": 1,
                "TaskDefinition": {
                    "Fn::Sub": "${MytaskTask}"
                },
                "NetworkConfiguration": {
                    "AwsvpcConfiguration": {
                        "AssignPublicIp": "DISABLED",
                        "SecurityGroups": [],
                        "Subnets": ["subnet-2cc37974", "subnet-3c959d5b", "subnet-49d7d200"]
                    }
                }
            }
        }

Serverless.yml


frameworkVersion: ">=1.1.0"

plugins:
  - serverless-fargate-tasks
  # - serverless-vpc-plugin
custom:
  bucket: jb-mp-sls
  fargate:
    vpc:
      subnets:
        - subnet-2cc37974
        - subnet-3c959d5b
        - subnet-49d7d200
    tasks:
      my-task:
        image: mountainpass/infrastructure:helloworld

  # vpcConfig:
  #   zones:
  #     - ap-southeast-2a
  #     # - ap-southeast-2b
  #     # - ap-southeast-2c

provider:
  name: aws
  region: ap-southeast-2
  runtime: nodejs12.x
  iamRoleStatements:
    - Effect: Allow
      Action:
        - s3:*
      Resource: "*"

functions:
  postprocess:
    handler: handler.postprocess
    events:
      - s3:
          bucket: ${self:custom.bucket}
          event: s3:ObjectCreated:*
          rules:
            - suffix: .png
nickgrealy commented 3 years ago

Just to clarify (re: above) - we're using this plugin with serverless.yml to create a fargate Task Definition.

We generated the cloudformation template using sls package (it can also be seen in the AWS dashboard).

I suspect it might be this same issue -> (Solution: Service reference TaskDef using ARN?): https://stackoverflow.com/questions/32727520/cloudformation-template-for-creating-ecs-service-stuck-in-create-in-progress