Error defining a task on Amazon Container Service - amazon-web-services

But to run the
aws ecs register-task-definition --family --container-definitions wordpress file: //wordpress.json"
is giving the following error below:
Error parsing parameter '--container-definitions': Invalid JSON: Expecting object: line 1 column 1 (char 0)
JSON received: {
My wordpress.json:
{
"containerDefinitions": [
{
"name": "wordpress",
"links": [
"mysql"
],
"image": "wordpress",
"essential": true,
"portMappings": [
{
"containerPort": 80,
"hostPort": 80
}
],
"memory": 500,
"cpu": 10
},
{
"environment": [
{
"name": "MYSQL_ROOT_PASSWORD",
"value": "password"
}
],
"name": "mysql",
"image": "mysql",
"cpu": 10,
"memory": 500,
"essential": true
}
],
"family": "wordpress"
}
Any suggestions?

The correct aws cli command for registration of the Task is
aws ecs register-task-definition --cli-input-json file://wordpress.json

Related

Finding the values for executionRoleArn, taskRoleArn

I'm working through an AWS Python tutorial, module 2.
I'm at the point Section C, where I have to create a task definition by filling in some REPLACE_ME values in a json file.
{
"family": "mythicalmysfitsservice",
"cpu": "256",
"memory": "512",
"networkMode": "awsvpc",
"requiresCompatibilities": [
"FARGATE"
],
"executionRoleArn": "REPLACE_ME_ECS_SERVICE_ROLE_ARN",
"taskRoleArn": "REPLACE_ME_ECS_TASK_ROLE_ARN",
"containerDefinitions": [
{
"name": "MythicalMysfits-Service",
"image": "REPLACE_ME_IMAGE_TAG_USED_IN_ECR_PUSH",
"portMappings": [
{
"containerPort": 8080,
"protocol": "http"
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "mythicalmysfits-logs",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "awslogs-mythicalmysfits-service"
}
},
"essential": true
}
]
}
There are three variables I'm not sure where to get the values:
"REPLACE_ME_ECS_SERVICE_ROLE_ARN",
"REPLACE_ME_ECS_TASK_ROLE_ARN",
"REPLACE_ME_IMAGE_TAG_USED_IN_ECR_PUSH"
Before this step, in steps A and B, I create-cluster, but the output of that doesn't indicate obvious values to me:
$ aws ecs create-cluster --cluster-name MythicalMysfits-Cluster
{
"cluster": {
"clusterArn": "arn:aws:ecs:us-east-1:002847010850:cluster/MythicalMysfits-Cluster",
"clusterName": "MythicalMysfits-Cluster",
"status": "ACTIVE",
"registeredContainerInstancesCount": 0,
"runningTasksCount": 0,
"pendingTasksCount": 0,
"activeServicesCount": 0,
"statistics": [],
"tags": [],
"settings": [
{
"name": "containerInsights",
"value": "disabled"
}
],
"capacityProviders": [],
"defaultCapacityProviderStrategy": []
}
}
The only value I suspect I might know is, "REPLACE_ME_IMAGE_TAG_USED_IN_ECR_PUSH" which i could take from docker push 002847010850.dkr.ecr.us-east-1.amazonaws.com/mythicalmysfits/service when I pushed a docker image to the Elastic Compute Repository
So I made a guess and used the "clusterArn" value for both REPLACE_ME's, and the original image tag for the third but
$ aws ecs register-task-definition --cli-input-json file://~/environment/aws-modern-application-workshop/module-2/aws-cli/task-definition.json
An error occurred (ClientException) when calling the RegisterTaskDefinition operation: Role is not valid
This is the json I fed it:
{
"family": "mythicalmysfitsservice",
"cpu": "256",
"memory": "512",
"networkMode": "awsvpc",
"requiresCompatibilities": [
"FARGATE"
],
"executionRoleArn": "arn:aws:ecs:us-east-1:002847010850:cluster/MythicalMysfits-Cluster",
"taskRoleArn": "arn:aws:ecs:us-east-1:002847010850:cluster/MythicalMysfits-Cluster",
"containerDefinitions": [
{
"name": "MythicalMysfits-Service",
"image": "002847010850.dkr.ecr.us-east-1.amazonaws.com/mythicalmysfits/service",
"portMappings": [
{
"containerPort": 8080,
"protocol": "http"
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "mythicalmysfits-logs",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "awslogs-mythicalmysfits-service"
}
},
"essential": true
}
]
}
Can anyone advise where I'm going wrong here? This tutorial is pretty lousy -- just a bunch of incantations, very brittle, and no obvious forum discussions to work through it.
Marcin's suggestion of an answer caused me to to rethink and look at a JSON output from earlier in the tutorial.
aws cloudformation describe-stacks --stack-name MythicalMysfitsCoreStack gives a pile of key/value pairs and both REPLACE_ME_ECS_SERVICE_ROLE_ARN REPLACE_ME_ECS_TASK_ROLE_ARN OutputValues are inside there.
Then the procedure works.

Getting error "At least one of 'memory' or 'memoryReservation' must be specified" on AWS

AWS is giving error "Service:AmazonECS, Code:ClientException, Message:Invalid setting for container 'frontend'. At least one of 'memory' or 'memoryReservation' must be specified"
below is dockerrun.aws.json
{
"AWSEBDockerrunVersion": 2,
"containerDefinitions": [
{
"name": "frontend",
"image": "abc/frontend",
"memory": 128,
"hostname": "frontend",
"essential": true
},
{
"name": "server",
"image": "abc/"server",
"memory": 128,
"hostname": ""server",
"essential": true
}
],
"links": ["frontend", "server"],
"memory": 128
}

Getting "reason": "RESOURCE:PORTS" when running Jenkins build

when I run a Jenkins build, my back-end code is not updating in AWS. There seems to be an error when I try to build the Elastic Beanstalk:
Encountered error starting new ECS task: { "failures": [ { "reason": "RESOURCE:PORTS", "arn": "arn:aws:ecs:eu-west-1:863820595425:container-instance/d6b92955-eb16-4911-b874-683155fcd630" } ], "tasks": [] }
Has anyone encountered this before? The port set up in the dockerrun.aws.json file has not been changed in over a year. If I manually restart Task Definitions this backend will eventually update but I need to see why the Ports issue is happening.
My dockerrrun.aws.json file:
{
"AWSEBDockerrunVersion": 2,
"containerDefinitions": [
{
"name": "customerportal-backend",
"image": "<AWS_ACCOUNT_ID>.dkr.ecr.eu-west-1.amazonaws.com/<ECR_REPO_NAME>:latest",
"essential": true,
"memory": 1024,
"portMappings": [
{
"hostPort": 80,
"containerPort": 3001
}
],
"mountPoints": [
{
"sourceVolume": "store-efs",
"containerPath": "/efs-mount-point"
}
],
"links": [
"clamav-rest"
]
},
{
"name": "clamav-server",
"image": "mkodockx/docker-clamav:latest",
"essential": true,
"memory": 1536
},
{
"name": "clamav-rest",
"image": "lokori/clamav-rest",
"essential": true,
"memory": 1024,
"links": [
"clamav-server:clamav-server"
],
"portMappings": [
{
"hostPort": 3100,
"containerPort": 8080
}
],
"environment" : [
{ "name" : "CLAMD_HOST", "value" : "clamav-server" }
]
}
],
"volumes": [
{
"name" : "store-efs",
"host": {
"sourcePath": "/var/app/efs"
}
}
]
}

No volumes are attached to running mysql docker container - AWS Elastic beanstalk multi container docker app

My current approach:
The Dockerrun.aws.json file looks like this:
{
"AWSEBDockerrunVersion": 2,
"volumes": [
{
"name": "mysql-volume",
"host": {
"sourcePath": "/var/app/current/web-app"
}
}
],
"containerDefinitions": [
{
"name": "mysql",
"image": "mysql:5.7",
"environment": [
{
"name": "MYSQL_ROOT_PASSWORD",
"value": "root"
},
{
"name": "MYSQL_USER",
"value": "user"
},
{
"name": "MYSQL_PASSWORD",
"value": "pass"
},
{
"name": "MYSQL_DATABASE",
"value": "db"
}
],
"essential": true,
"memory": 256,
"portMappings": [
{
"hostPort": 3306,
"containerPort": 3306
}
],
"mountPoints": [
{
"sourceVolume": "mysql-volume",
"containerPath": "/var/lib/mysql"
}
]
},
{
"name": "web-application",
"image": "some image",
"essential": true,
"memory": 512,
"portMappings": [
{
"hostPort": 80,
"containerPort": 8080
}
],
"links": [
"mysql"
]
}
]
}
When I connect via SSH to EC2 instance I see that no volumes are created. Not sure, what's the reason and how can I change the Dockerrrun.aws.json file to make it work. Also, when I stop and restart the instance the data is lost

AWS ECS docker Invalid 'volumesFrom' setting. Unknown container

I am trying to run service with following definition on AWS ECS cluster. But I am getting an error. Invalid 'volumesFrom' setting. Unknown container: 'docker-data'. I have separately launched docker-data service but my other service is still unable to find my data container. Below are task definitions.
{
"containerDefinitions": [{
"name": "docker-data",
"image": "jaigouk/data-only-container",
"memory": 128
}],
"family": "docker-data"
}
{
"containerDefinitions": [{
"image": "my/work-image",
"name": "image2",
"memory": 512,
"portMappings": [{
"hostPort": 8040,
"containerPort": 8040,
"protocol": "tcp"
}],
"volumesFrom": [{
"sourceContainer": "docker-data"
}]
}],
"family": "console"
}
Looks like you're defining 2 containers in two task definitions. In this case, docker-data is not known.
Here is one of my working example
{
"taskDefinitionArn":"arn:aws:ecs:ap-southeast-1:xxxx:task-definition/vc-p-tim:15",
"networkMode":"bridge",
"status":"ACTIVE",
"revision":15,
"taskRoleArn":null,
"containerDefinitions":[
{
"volumesFrom":[
],
"memory":2048,
"extraHosts":null,
"dnsServers":null,
"disableNetworking":null,
"dnsSearchDomains":null,
"hostname":null,
"essential":true,
"entryPoint":null,
"mountPoints":[
{
"containerPath":"/apps",
"sourceVolume":"tinymce-data",
"readOnly":null
}
],
"name":"tim-srv",
"ulimits":null,
"dockerSecurityOptions":null,
"environment":[
],
"links":null,
"workingDirectory":null,
"readonlyRootFilesystem":null,
"image":"xxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com/tinymce-server:latest",
"command":null,
"user":null,
"dockerLabels":null,
"logConfiguration":null,
"cpu":0,
"privileged":null,
"memoryReservation":null
},
{
"volumesFrom":[
{
"readOnly":null,
"sourceContainer":"tim-srv"
}
],
"memory":256,
"extraHosts":null,
"dnsServers":null,
"disableNetworking":null,
"dnsSearchDomains":null,
"hostname":null,
"essential":true,
"entryPoint":null,
"mountPoints":[
],
"name":"tim-api",
"ulimits":null,
"dockerSecurityOptions":null,
"links":null,
"workingDirectory":null,
"readonlyRootFilesystem":null,
"image":"xxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com/tinymce-api:0118171510",
"command":null,
"user":null,
"dockerLabels":null,
"logConfiguration":null,
"cpu":0,
"privileged":null,
"memoryReservation":null
}
],
"volumes":[
{
"host":{
"sourcePath":"tinymce-data"
},
"name":"tinymce-data"
}
],
"family":"vc-p-tim"
}