1

I built a Docker container that runs locally without error. When I deploy to AWS Fargate, the container runs, but throws runtime Javascript errors that don't appear when running locally. For example:

const fcl = require( '@onflow/fcl' );
const storefrontAddress = 0x9a0766d93b6608b7;
const eventOfferMade = `A.${ fcl.sansPrefix( storefrontAddress ) }.SaleOfferAvailable`;

This does not throw an error when the container is run locally, but throws n.replace is not a function when the container runs on Fargate. fcl.sansPrefix expects a String, not a hex number, and throws the error. I can coerce the number to a string as follows and it will run on Fargate:

const eventOfferMade = `A.${ fcl.sansPrefix( String.toString( storefrontAddress )) }.SaleOfferAvailable`;

Is this container somehow shifting into "use strict" mode? Is it using a different Javascript engine on Fargate? Is there a kernel dependency that could cause something like this?

Insights appreciated! Thanks!

Container is FROM node:18.4-alpine3.16, built on Ubuntu 18.04 with Docker version:

Client: Docker Engine - Community
 Cloud integration: v1.0.24
 Version:           20.10.18
 API version:       1.41
 Go version:        go1.18.6
 Git commit:        b40c2f6
 Built:             Thu Sep  8 23:11:34 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.18
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.6
  Git commit:       e42327a
  Built:            Thu Sep  8 23:09:28 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.8
  GitCommit:        9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Edit, in reply to Mark B: The container is deployed to ECS via Copilot. The task definition is:

{
  "ipcMode": null,
  "executionRoleArn": "arn:aws:iam::445530232977:role/geosvc-test-geowebsvr-ExecutionRole-1U946MJKGD7TT",
  "containerDefinitions": [
    {
      "dnsSearchDomains": [],
      "environmentFiles": null,
      "logConfiguration": {
        "logDriver": "awslogs",
        "secretOptions": null,
        "options": {
          "awslogs-group": "/copilot/geosvc-test-geowebsvr",
          "awslogs-region": "us-west-2",
          "awslogs-stream-prefix": "copilot"
        }
      },
      "entryPoint": [],
      "portMappings": [
        {
          "hostPort": 8080,
          "protocol": "tcp",
          "containerPort": 8080
        }
      ],
      "command": [],
      "linuxParameters": null,
      "cpu": 0,
      "environment": [
        {
          "name": "COPILOT_APPLICATION_NAME",
          "value": "geosvc"
        },
        {
          "name": "COPILOT_ENVIRONMENT_NAME",
          "value": "test"
        },
        {
          "name": "COPILOT_LB_DNS",
          "value": "geosv-Publi-WFRGPHEB1KSL-217029508.us-west-2.elb.amazonaws.com"
        },
        {
          "name": "COPILOT_SERVICE_DISCOVERY_ENDPOINT",
          "value": "test.geosvc.local"
        },
        {
          "name": "COPILOT_SERVICE_NAME",
          "value": "geowebsvr"
        }
      ],
      "resourceRequirements": null,
      "ulimits": null,
      "dnsServers": [],
      "mountPoints": [],
      "workingDirectory": null,
      "secrets": null,
      "dockerSecurityOptions": [],
      "memory": null,
      "memoryReservation": null,
      "volumesFrom": [],
      "stopTimeout": null,
      "image": "445530232977.dkr.ecr.us-west-2.amazonaws.com/geosvc/geowebsvr@sha256:049cddcf8755a19f720a1ee27c7a33300f7b0bcdc7be5800f1bb9f1bcff1df2d",
      "startTimeout": null,
      "firelensConfiguration": null,
      "dependsOn": null,
      "disableNetworking": null,
      "interactive": null,
      "healthCheck": null,
      "essential": true,
      "links": [],
      "hostname": null,
      "extraHosts": null,
      "pseudoTerminal": null,
      "user": null,
      "readonlyRootFilesystem": null,
      "dockerLabels": null,
      "systemControls": [],
      "privileged": null,
      "name": "geowebsvr"
    }
  ],
  "placementConstraints": [],
  "memory": "1024",
  "taskRoleArn": "arn:aws:iam::445530232977:role/geosvc-test-geowebsvr-TaskRole-9S1YXNWDGRHK",
  "compatibilities": [
    "EC2",
    "FARGATE"
  ],
  "taskDefinitionArn": "arn:aws:ecs:us-west-2:445530232977:task-definition/geosvc-test-geowebsvr:107",
  "family": "geosvc-test-geowebsvr",
  "requiresAttributes": [
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "ecs.capability.execution-role-awslogs"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.ecr-auth"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.docker-remote-api.1.17"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.docker-remote-api.1.21"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.task-iam-role"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "ecs.capability.execution-role-ecr-pull"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "ecs.capability.task-eni"
    }
  ],
  "pidMode": null,
  "requiresCompatibilities": [
    "FARGATE"
  ],
  "networkMode": "awsvpc",
  "runtimePlatform": null,
  "cpu": "256",
  "revision": 107,
  "status": "ACTIVE",
  "inferenceAccelerators": null,
  "proxyConfiguration": null,
  "volumes": []
}
HieroB
  • 3,917
  • 4
  • 17
  • 22
  • Assuming ECS and not EKS, how do you deploy the container to ECS exactly? Can you show the ECS Task Definition? Perhaps there's a difference in the `ENTRYPOINT` or `CMD` when the container is running on ECS? – Mark B Oct 06 '22 at 13:50
  • Mark B thanks!, I am deploying to ECS via Copilot. Added the Task Definition to the post. I don't see anything specific there--the CMD to run the app is defined in the Docker image, which is the same on both platforms. In the CloudFormation, the stack update is initiated by a Lambda function, and I noticed it specifies a runtime of nodejs12.x, which is pretty old. But I'm not sure the stack update actually takes place in that context, or if it would have any effect. As noted above, my ctr is built from node18.4-alpine3.16, so that should define the runtime nodejs context. – HieroB Oct 06 '22 at 19:29

0 Answers0