0

Based on instructions in the official documentation and the official docker image I am running Elasticsearch locally with these configurations via docker compose:

elasticsearch:
  image: 'elasticsearch:6.7.1'
  container_name: elasticsearch
  environment:
    - cluster.name=docker-cluster
    - bootstrap.memory_lock=true
    - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
  ulimits:
    memlock:
      soft: -1
      hard: -1
  volumes:
    - esdata1:/usr/share/elasticsearch/data
  ports:
    - 9200:9200

With this running successfully locally I am now looking into running this in AWS ECS both in the EC2 and Fargate configurations. That said I created a Cloudformation template that has a TaskDefinition that has a ContainerDefinition for Elasticsearch that looks like this:

ContainerDefinition:
  - Name: 'elasticsearch'
      Image: 'elasticsearch:6.7.1'
      LogConfiguration:
        LogDriver: awslogs
        Options:
          awslogs-group: !Ref 'LogGroup'
          awslogs-region: 'us-west-2'
          awslogs-stream-prefix: !Sub 'elasticsearch'
      Environment:
      - Name: cluster.name
        Value: 'docker-cluster'
      - Name: bootstrap.memory_lock
        Value: 'true'
      - Name: ES_JAVA_OPTS
        Value: '-Xms512m -Xmx512m'
      Cpu: '1024'
      Memory: '4096'
      Ulimits:
      - Name: 'memlock'
      - SoftLimit: -1
      - HardLimit: -1
      MountPoints:
      - SourceVolume: esdata1
        ContainerPath: /usr/share/elasticsearch/data
      PortMappings:
      - HostPort: '9200'
        ContainerPort: '9200'

Launching the creation of my Cloudformation stack with this template results in the following Cloudformation error:

CREATE_FAILED   AWS::ECS::TaskDefinition    TaskDefinition  Property HardLimit cannot be empty.

When I comment out the following piece of configuration:

  Ulimits:
  - Name: 'memlock'
  - SoftLimit: -1
  - HardLimit: -1

and launch the creation of my Cloudformation stack everything on a Cloudformation perspective is successful and no errors are encountered which tells me besides the Ulimits configuration I should be doing good. From there I took a look at the AWS Cloudformation ContainerDefinition documentation which mentions the following about the Ulimits configuration:

This parameter requires version 1.18 of the Docker Remote API or greater on your container instance.

I am not sure why I am getting this error HardLimit cannot be empty. but was wondering if it had to do with the container needing the Docker Remote API. I am a bit confused at this point but if anyone has any information about how to get this working would love to hear about it. My knowledge of Docker Remote API is not so great and also maybe this error has nothing to do with that at all. Sometimes Cloudformation error messages are not entirely clear, just trying to get past this point so throwing out there all the information I got. Thanks

nabello
  • 716
  • 11
  • 29

1 Answers1

3

Your YML configuration is mistaken. Each time you have a new line with a -, it will create a new entry. In JSON format, your YML would look like:

  "Ulimits": [{
    "Name": "memlock"
  },{
    "SoftLimit": -1
  },{
    "HardLimit": -1
  }]

Try instead:

  Ulimits:
  - Name: 'memlock'
    SoftLimit: -1
    HardLimit: -1
Nick Lassonde
  • 213
  • 1
  • 7