39
loading...
This website collects cookies to deliver better user experience
FROM amazoncorretto:11 as builder
COPY . /srv
WORKDIR /srv
RUN ./mvnw package spring-boot:repackage
FROM amazoncorretto:11
COPY --from=builder /srv/target/spring-boot-demo-1.0.0.jar /srv/
EXPOSE 8080
ENTRYPOINT ["java","-jar", "/srv/spring-boot-demo-1.0.0.jar"]
In the example below, I am checking the repository out after swtiching to a separate folder off my home folder in a directory called blog-demo [cd ~/blog-demo]
cd ~
mkdir blog-demo
cd ~/blog-demo
git clone https://github.com/094459/blog-multi-arch-springboot.git
cd blog-multi-arch-springboot/demo-multiarch-springboot-multiarch
AWS_DEFAULT_REGION={your AWS region}
AWS_ACCOUNT={your AWS account number}
AWS_ECR_REPO=demo-multiarch-springboot-ecsanywhere
AWS_CC_REPO=demo-multiarch-springboot-ecsanywhere
COMMIT_HASH="abcdef"
...
...
The push refers to repository [704533066374.dkr.ecr.eu-west-1.amazonaws.com/demo-multiarch-springboot-ecsanywhere-test]
05aeb36b29bc: Pushed
# create AWS ECR Repo
91a6dcd86b53: Pushed
ec1372e9de86: Pushed
abcdef-arm64: digest: sha256:f51d9da34442fb53f67439752754fd36e02406d061db0a574429e6ecf94d9689 size: 954
Created manifest list 704533066374.dkr.ecr.eu-west-1.amazonaws.com/demo-multiarch-springboot-ecsanywhere-test:abcdef
{
"schemaVersion": 2,
"mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
"manifests": [
{
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"size": 954,
"digest": "sha256:28ad0b732b826e8a27575715b3d922c4ce0065749be31af7325ab5f96c5fba9b",
"platform": {
"architecture": "amd64",
"os": "linux"
}
},
{
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"size": 954,
"digest": "sha256:f51d9da34442fb53f67439752754fd36e02406d061db0a574429e6ecf94d9689",
"platform": {
"architecture": "arm64",
"os": "linux"
}
}
]
}
cd ~/blog-demo
git clone https://git-codecommit.eu-west-1.amazonaws.com/v1/repos/demo-multiarch-springboot-ecsanywhere-test demo-app
cd demo-app
cp -r ~/blog-demo/blog-multi-arch-springboot/demo-multiarch-springboot-multiarch/* .
├── cdk-app
│ └── ecs-anywhere
│ ├── app.py
│ ├── ecs_anywhere
│ │ ├── ecs_anywhere_cicd.py
│ │ ├── ecs_anywhere_ecs.py
│ │ ├── ecs_anywhere_pipe.py
│ │ ├── ecs_anywhere_repo.py
│ │ └── ecs_anywhere_vpc.py
│ └── requirements.txt
├── pipeline
│ ├── ecs-pipeline
│ └── eks-pipeline
├── setup.sh
└── springbootdemo
├── Dockerfile
├── mvnw
├── pom.xml
├── src
│ └── main
│ ├── java
│ │ └── hello
│ │ ├── Application.java
│ │ └── HelloController.java
│ └── resources
│ └── static
│ ├── css
│ │ └── style.css
│ └── images
│ ├── arm.png
│ ├── aws.png
│ └── intel.png
├── tf-any.json
├── tf.json
└── tf.json.template
git checkout -b main
git add .
git commit -m "Initial upload"
git push --set-upstream origin main
Note! If you get prompted for username/password, then you may not have the CodeCommit Git helper configured. Check out the documented linked above. In your .gitconfig file I have the following setup
> [credential]
> helper =
> helper = !aws codecommit credential-helper $@
> UseHttpPath = true
>
>[user]
> email = [email protected]
> name = xxxx
>
[optional] You can change the default branch to Main. This is much easier to do via the console, where you go to the repository (demo-multiarch-springboot-ecsanywhere-test) create a branch (main) and then go to settings and make this the default branch.
cd ~/blog-demo/blog-multi-arch-springboot/demo-multiarch-springboot-multiarch/cdk-app/ecs-anywhere
from aws_cdk import core
from ecs_anywhere.ecs_anywhere_cicd import EcsAnywhereCICDStack
from ecs_anywhere.ecs_anywhere_vpc import EcsAnywhereVPCStack
from ecs_anywhere.ecs_anywhere_ecs import EcsAnywhereECSStack
from ecs_anywhere.ecs_anywhere_pipe import EcsAnywherePipeStack
from ecs_anywhere.ecs_anywhere_repo import EcsAnywhereLBStack
env_EU=core.Environment(region="eu-west-1", account="704533066374")
props = {
'mydcexternalip': '79.67.110.xx',
'mydcinternalcidr' : '192.168.1.0/24',
'awsvpccidr':'10.0.0.0/16',
'ecsclustername':'mydc-ecs',
'ecr-repo': 'demo-multiarch-springboot-ecsanywhere',
'code-repo' : 'demo-multiarch-springboot-multiarch',
'image-tag' : 'abcdef',
'home-pi' : '192.168.1.99'
}
app = core.App()
mydc_vpc = EcsAnywhereVPCStack(
scope=app,
id="ecs-anywhere-vpc",
env=env_EU,
props=props
)
mydc_lb = EcsAnywhereLBStack(
scope=app,
id="ecs-anywhere-lb",
env=env_EU,
vpc=mydc_vpc.vpc,
props=props
)
mydc_ecs_cicd = EcsAnywhereCICDStack(
scope=app,
id="ecs-anywhere-cicd",
env=env_EU,
vpc=mydc_vpc.vpc,
props=props
)
mydc_ecs_pipe = EcsAnywherePipeStack(
scope=app,
id="ecs-anywhere-pipe",
env=env_EU,
vpc=mydc_vpc.vpc,
props=props
)
mydc_ecs = EcsAnywhereECSStack(
scope=app,
id="ecs-anywhere-cfn",
env=env_EU,
vpc=mydc_vpc.vpc,
props=props
)
app.synth()
env_EU=core.Environment(region="{your aws region}", account="{your aws account}")
props = {
'mydcexternalip': '{your external router IP - you can find this via tools like what is my IP}',
'mydcinternalcidr' : '{your home network CIDR e.g.192.168.1.0/24}',
'awsvpccidr':'{your VPC CIDR range e.g 10.0.0.0/16}',
'ecsclustername':'{name for your ecs cluster e.g. mydc-ecs}',
'ecr-repo': '{name of the ECR repo - must match what you set in the setup.sh e.g. demo-multiarch-springboot-ecsanywhere}',
'code-repo' : '{name of the CodeCommit repo - must match what you setup above, e.g. demo-multiarch-springboot-multiarch}',
'image-tag' : '{initial hash for ECR repo - must match what you have setup above, e.g. abcdef}'
}
'home-pi' : '{the IP address of the Raspberry Pi you will be running your workloads on your local network}
cdk ls
ecs-anywhere-cfn
ecs-anywhere-pipe
ecs-anywhere-vpc
ecs-anywhere-cicd
ecs-anywhere-lb
cdk deploy ecs-anywhere-vpc
✅ ecs-anywhere-vpc
Outputs:
ecs-anywhere-vpc.ExportsOutputRefmydcvpnvpcC99028A5E0C4BB86 = vpc-0e77901855dd34b64
ecs-anywhere-vpc.ExportsOutputRefmydcvpnvpcprivateSubnet1Subnet907447937118DADD = subnet-00d3e62f014db2eb2
ecs-anywhere-vpc.ExportsOutputRefmydcvpnvpcprivateSubnet2Subnet2F863D5508703380 = subnet-084ab056d6ab1ae1a
ecs-anywhere-vpc.ExportsOutputRefmydcvpnvpcpublicSubnet1Subnet93B9609B6FB2CB58 = subnet-0eb59347bf659e8d0
ecs-anywhere-vpc.ExportsOutputRefmydcvpnvpcpublicSubnet2Subnet252458EC3B8C529C = subnet-038234a8a8bffb90a
ecs-anywhere-vpc.VPCId = vpc-0e77901855dd34b64
ecs-anywhere-vpc.VPGId = vgw-0bc980838a7a37eda
Stack ARN:
arn:aws:cloudformation:eu-central-1:704533066374:stack/ecs-anywhere-vpc/a5f78e70-e28e-11eb-90fc-026316002c84
cdk deploy ecs-anywhere-cicd
✅ ecs-anywhere-cicd
Outputs:
ecs-anywhere-cicd.LoadBalancerEndpoint = ecs-a-LB8A1-UQ0ZD3461WUB-1638849351.eu-central-1.elb.amazonaws.com
Stack ARN:
arn:aws:cloudformation:eu-central-1:704533066374:stack/ecs-anywhere-cicd/7004c1a0-e290-11eb-9334-0288a08f1e2c
cdk deploy ecs-anywhere-pipeline
✅ ecs-anywhere-pipe
Outputs:
ecs-anywhere-pipe.CodeCommitOutput = https://git-codecommit.eu-central-1.amazonaws.com/v1/repos/demo-springboot-repo
Stack ARN:
arn:aws:cloudformation:eu-central-1:704533066374:stack/ecs-anywhere-pipe/30f90840-e29a-11eb-b20f-0ae3cbe3a3b6
version: 0.2
phases:
pre_build:
commands:
- echo Logging in to Amazon ECR...
- aws --version
- $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- IMAGE_TAG=${COMMIT_HASH:=latest}
- ARM_TAG=${IMAGE_TAG}-arm64
- AMD_TAG=${IMAGE_TAG}-amd64
- echo $REPOSITORY_URI
- echo $IMAGE_TAG
- echo $AMD_TAG
- echo $ARM_TAG
- export DOCKER_CLI_EXPERIMENTAL=enabled
build:
commands:
- echo Build started on `date`
- echo Building the Docker manifest...
- docker manifest create $REPOSITORY_URI:$IMAGE_TAG $REPOSITORY_URI:$ARM_TAG $REPOSITORY_URI:$AMD_TAG
- docker manifest annotate --arch arm64 $REPOSITORY_URI:$IMAGE_TAG $REPOSITORY_URI:$ARM_TAG
- docker manifest annotate --arch amd64 $REPOSITORY_URI:$IMAGE_TAG $REPOSITORY_URI:$AMD_TAG
- docker manifest inspect $REPOSITORY_URI:$IMAGE_TAG
- docker manifest push $REPOSITORY_URI:$IMAGE_TAG
post_build:
commands:
- cd springbootdemo
- sed -i "s|{ecr_image}|${REPOSITORY_URI}:${IMAGE_TAG}|g" tf.json
- sed -i "s|{region}|$AWS_DEFAULT_REGION|g" tf.json
- sed -i "s|{log_group}|$ECS_SN|g" tf.json
- aws ecs register-task-definition --cli-input-json file://tf.json
- TASK_DEFINITON="springboot-cicd"
- TASK_REVISION=`aws ecs describe-task-definition --task-definition $TASK_DEFINITON | egrep "revision" | tr "/" " " | awk '{print $2}' | sed 's/,$//'`
- aws ecs update-service --cluster $ECS_CLUSTER --service $ECS_SERVICE --task-definition $TASK_DEFINITON:${TASK_REVISION}
- aws ssm put-parameter --name "/demo/ecsanywhere/latestimage" --value ${IMAGE_TAG} --type "String" --overwrite
There are a number of great blog posts I read whilst preparing this post, which you should check out. The first is from Romain Jourdan Secure Connection between AWS VPC and a Raspberry Pi, but there are a few others that are worth mentioning. This blog post from Nathan Peck, Building an Amazon ECS Anywhere home lab with Amazon VPC network connectivity and this post Look ma, I can run containers on Amazon ECS Anywhere — On-premises or on the Cloud !!. Finally, this great post, Setup Raspberry PI 3 as AWS VPN Customer Gateway helped get me unstuck when I had VPN issues.
Make sure you check them out if you get stuck or want to dive a little deeper into this setup.
If you have a different VPN Gateway (for example, if you are using a Unify type solution, then check out this Romain Jourdan blog post above).
uname-a output
Linux dmcpi01 5.10.44-v7+ #1428 SMP Thu Jun 24 17:22:49 BST 2021 armv7l GNU/Linux
uname -a
Linux ubuntu 5.4.0-1038-raspi #41-Ubuntu SMP PREEMPT Thu Jun 17 14:14:11 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux
net.ifnames=0 dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=LABEL=writable rootfstype=ext4 elevator=deadline rootwait fixrtc cgroup_enable=memory
sudo apt-get update
sudo apt-get install strongswan raspberrypi-kernel-headers lsof
sudo ipsec status
sudo ip link add Tunnel1 type vti local 192.168.1.6 remote 35.156.20.208 key 100
sudo ip addr add 169.254.100.230/30 remote 169.254.100.229/30 dev Tunnel1
sudo ip link set Tunnel1 up mtu 1419
sudo ip route add 10.0.0.0/16 dev Tunnel1 metric 100
sudo iptables -t mangle -A FORWARD -o Tunnel1 -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
sudo iptables -t mangle -A INPUT -p esp -s 35.156.20.208 -d 79.67.110.164 -j MARK --set-xmark 100
sudo ip link add Tunnel2 type vti local 192.168.1.6 remote 52.58.162.102 key 200
sudo ip addr add 169.254.254.234/30 remote 169.254.254.233/30 dev Tunnel2
sudo ip link set Tunnel2 up mtu 1419
sudo ip route add 10.0.0.0/16 dev Tunnel2 metric 200
sudo iptables -t mangle -A FORWARD -o Tunnel2 -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
sudo iptables -t mangle -A INPUT -p esp -s 52.58.162.102 -d 79.67.110.164 -j MARK --set-xmark 200
Tunnel1 Link encap:IPIP Tunnel HWaddr
inet addr:169.254.100.230 P-t-P:169.254.100.229 Mask:255.255.255.252
inet6 addr: fe80::5efe:c0a8:106/64 Scope:Link
UP POINTOPOINT RUNNING NOARP MTU:1419 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:8 dropped:0 overruns:0 carrier:8
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Tunnel2 Link encap:IPIP Tunnel HWaddr
inet addr:169.254.254.234 P-t-P:169.254.254.233 Mask:255.255.255.252
inet6 addr: fe80::5efe:c0a8:106/64 Scope:Link
UP POINTOPOINT RUNNING NOARP MTU:1419 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:3 dropped:0 overruns:0 carrier:3
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 wlan0
10.0.0.0 0.0.0.0 255.255.0.0 U 0 0 0 Tunnel1
10.0.0.0 0.0.0.0 255.255.0.0 U 0 0 0 Tunnel2
169.254.100.228 0.0.0.0 255.255.255.252 U 0 0 0 Tunnel1
169.254.254.232 0.0.0.0 255.255.255.252 U 0 0 0 Tunnel2
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0
Note! This information is not persistent. If you restart your Pi, you will need to repeat these steps. Read the text file for details of how you can persist the configuration
sudo ipsec start
sudo ipsec status
Security Associations (2 up, 0 connecting):
Tunnel2[2]: ESTABLISHED 3 seconds ago, 192.168.1.6[80.42.49.11]...18.184.143.185[18.184.143.185]
Tunnel2{2}: INSTALLED, TUNNEL, ESP in UDP SPIs: c6777c18_i c9f1bf73_o
Tunnel2{2}: 0.0.0.0/0 === 0.0.0.0/0
Tunnel1[1]: ESTABLISHED 3 seconds ago, 192.168.1.6[80.42.49.11]...3.65.61.44[3.65.61.44]
Tunnel1{1}: INSTALLED, TUNNEL, ESP in UDP SPIs: c57f2982_i cbfd1699_o
Tunnel1{1}: 0.0.0.0/0 === 0.0.0.0/0
Note! If you see the following, then it is likely that you have entered the ipsec.conf/ipsec.security details incorrectly, so review that information.
Security Associations (2 up, 0 connecting):
Tunnel2[2]: CONNECTING, 192.168.1.6[%any]...52.58.162.102[%any]
Tunnel1[1]: CONNECTING, 192.168.1.6[%any]...35.156.20.208[%any]
sudo ip route add 10.0.0.0/16 via 192.168.1.6
Note! This is quite an important step. If the workload machine does not have a route back, during the later sections of this blog post, when you come to create a load balancer to this instance, you will get errors because the Pi does not know how to route traffic via the VPN.
Note! Whilst I was putting this together, my broadband went down. When it came back, my external IP had changed. I had to update the IP in the app.py and then redeploy the ecs-anywhere-vpc stack to update everything.
Note! Connectivity between AWS and our local environment is needed as the local instance is in essence being managed by the Amazon ECS control plane. Whilst it can tolerate some down time, after a few hours you will experience issues with your local environment. Therefore this is not (currently at least) intended for disconnected/infrequently connected environments.
cdk deploy ecs-anywhere-cfn
✅ ecs-anywhere-cfn
Outputs:
ecs-anywhere-cfn.ECSAnyWhereIamRole = ecs-anywhere-cfn-mydcecsroleE385F8F3-AI911P55T3JP
ecs-anywhere-cfn.ECSClusterName = mydc-ecs-extcluster
Stack ARN:
arn:aws:cloudformation:eu-central-1:704533066374:stack/ecs-anywhere-cfn/24fb74e0-e2fb-11eb-ae06-06c47aa6fac8
sudo apt-get install awscli
aws configure
aws ssm create-activation --iam-role ecs-anywhere-cfn-mydcecsroleE385F8F3-AI911P55T3JP --region={region} | tee ssm-activation.json
{
"ActivationId": "0c8840d6-cd71-482c-9ea5-3c8380cc325a",
"ActivationCode": "v4PEBr7nyIQ6u55OaWs!"
}
Note! Do not share these or store these electronically. I have changed these values and they will not work.
export id="0c8840d6-cd71-482c-9ea5-3c8380cc325a"
export code="v4PEBr7nyIQ6u55OaWs!"
Once you have these values, the clock is ticking. You will have a short amount of time in which to run the script (which will depend on how you have configured your AWS environment account timeouts). To know if this is the cause of any issues, you will see the following error in your logs like
> level=error time=2021-06-30T16:22:12Z msg="Unable to register as a container instance with ECS: ExpiredTokenException: The security token included in the request is expired\n\tstatus code: 400, request id: f21461d9-ba49-4097-a66c-a902747428c4" module=client.go
level=error time=2021-06-30T16:22:12Z msg="Error registering: ExpiredTokenException: The security token included in the request is expired\n\tstatus code: 400, request id: f21461d9-ba49-4097-a66c-a902747428c4" module=agent.go
>
curl --proto "https" -o ~/ecs-anywhere-install.sh "https://amazon-ecs-agent.s3.amazonaws.com/ecs-anywhere-install-latest.sh"
export ecscluster="mydc-ecs-extcluster"
sudo bash ~/ecs-anywhere-install.sh --region {your AWS region} --cluster $ecscluster --activation-id $id --activation-code $code
If you see the following error, make sure you have set your AWS region information correctly:
Error occurred fetching the seelog config file path: open /etc/amazon/ssm/seelog.xml: no such file or directory
Initializing new seelog logger
New Seelog Logger Creation Complete
2021-07-12 12:46:23 WARN Could not read InstanceFingerprint file: InstanceFingerprint does not exist.
2021-07-12 12:46:23 INFO No initial fingerprint detected, generating fingerprint file...
2021-07-12 12:46:25 ERROR Registration failed due to error registering the instance with AWS SSM. InvalidActivation:
...
...
Ping ECS Agent registered successfully! Container instance arn: "arn:aws:ecs:eu-west-1:704533066374:container-instance/ecs-anywhere-ec2-mydcecsclusterBB109425-r7l2mKClssuV/8dfb8700d9a1460dad403a321db6b5b9"
You can check your ECS cluster here https://console.aws.amazon.com/ecs/home?region=eu-west-1#/clusters/ecs-anywhere-ec2-mydcecsclusterBB109425-r7l2mKClssuV
# ok
##########################
##########################
This script installed three open source packages that all use Apache License 2.0.
You can view their license information here:
- ECS Agent https://github.com/aws/amazon-ecs-agent/blob/master/LICENSE
- SSM Agent https://github.com/aws/amazon-ssm-agent/blob/master/LICENSE
- Docker engine https://github.com/moby/moby/blob/master/LICENSE
##########################
Note! The first time that you launch the task, the Raspberry Pi will need to download the container images so it will take longer to start the application (and will vary depending on your internet connection). If you notice your Task is in "PENDING" then this could be the reason.
{
"requiresCompatibilities": [
"EXTERNAL"
],
"containerDefinitions": [{
"name": "springboot-remote",
"image": "{ecr_image}",
"memory": 256,
"cpu": 256,
"essential": true,
"portMappings": [{
"containerPort": 8080,
"hostPort": 8080,
"protocol": "tcp"
}]
}],
"networkMode": "bridge",
"family": "ecsanywhere"
}
export APP="704533066374.dkr.ecr.eu-central-1.amazonaws.com/demo-springboot-ecsanywhere:56beb49"
sed -i "s|{ecr_image}|$APP|g" tf-any.json
Note! If you are using a Mac, you will need to use "sed -i '.bak' "s|{ecr_image}|$APP|g" tf-any.json"
LOCAL_ECS_CLUSTER="mydc-ecs-extcluster"
LOCAL_ECS_SERVICE="mydc-ecs-svc"
LOCAL_TASK_DEFINITON="ecsanywhere"
aws ecs register-task-definition --cli-input-json file://tf-any.json --region={the region where the ECS cluster is running}
{
"taskDefinition": {
"taskDefinitionArn": "arn:aws:ecs:eu-central-1:704533066374:task-definition/ecsanywhere:5",
"containerDefinitions": [
{
"name": "springboot-remote",
"image": "704533066374.dkr.ecr.eu-central-1.amazonaws.com/demo-springboot-ecsanywhere:56beb49",
"cpu": 256,
"memory": 256,
"portMappings": [
{
"containerPort": 8080,
"hostPort": 8080,
"protocol": "tcp"
}
],
"essential": true,
"environment": [],
"mountPoints": [],
"volumesFrom": []
}
],
"family": "ecsanywhere",
"networkMode": "bridge",
"revision": 5,
"volumes": [],
"status": "ACTIVE",
"requiresAttributes": [
{
"name": "com.amazonaws.ecs.capability.ecr-auth"
}
],
"placementConstraints": [],
"compatibilities": [
"EXTERNAL",
"EC2"
],
"requiresCompatibilities": [
"EXTERNAL"
]
}
}
LOCAL_TASK_REVISION=`aws ecs describe-task-definition --task-definition $LOCAL_TASK_DEFINITON --region={the region where the ECS cluster is running} | egrep "revision" | tr "/" " " | awk '{print $2}' | sed 's/,$//'`
aws ecs update-service --cluster $LOCAL_ECS_CLUSTER --service $LOCAL_ECS_SERVICE --task-definition $LOCAL_TASK_DEFINITON:${LOCAL_TASK_REVISION} --region={the region where the ECS cluster is running}
{
"service": {
"serviceArn": "arn:aws:ecs:eu-central-1:704533066374:service/mydc-ecs-extcluster/mydc-ecs-svc",
"serviceName": "mydc-ecs-svc",
"clusterArn": "arn:aws:ecs:eu-central-1:704533066374:cluster/mydc-ecs-extcluster",
"loadBalancers": [],
"serviceRegistries": [],
"status": "ACTIVE",
"desiredCount": 1,
"runningCount": 1,
"pendingCount": 0,
"launchType": "EXTERNAL",
"taskDefinition": "arn:aws:ecs:eu-central-1:704533066374:task-definition/ecsanywhere:5",
"deploymentConfiguration": {
"deploymentCircuitBreaker": {
"enable": false,
"rollback": false
},
"maximumPercent": 200,
"minimumHealthyPercent": 100
},
"deployments": [
{
"id": "ecs-svc/2775386206525924918",
"status": "PRIMARY",
"taskDefinition": "arn:aws:ecs:eu-central-1:704533066374:task-definition/ecsanywhere:5",
"desiredCount": 1,
"pendingCount": 0,
"runningCount": 0,
"failedTasks": 0,
"createdAt": 1626102200.686,
"updatedAt": 1626102200.686,
"launchType": "EXTERNAL",
"rolloutState": "IN_PROGRESS",
"rolloutStateReason": "ECS deployment ecs-svc/2775386206525924918 in progress."
},
{
"id": "ecs-svc/7501839119011433935",
"status": "ACTIVE",
"taskDefinition": "arn:aws:ecs:eu-central-1:704533066374:task-definition/ecsanywhere:4",
"desiredCount": 1,
"pendingCount": 0,
"runningCount": 0,
"failedTasks": 2,
"createdAt": 1626101923.328,
"updatedAt": 1626101923.328,
"launchType": "EXTERNAL",
"rolloutState": "IN_PROGRESS",
"rolloutStateReason": "ECS deployment ecs-svc/7501839119011433935 in progress."
},
{
"id": "ecs-svc/5388566575203796106",
"status": "ACTIVE",
"taskDefinition": "arn:aws:ecs:eu-central-1:704533066374:task-definition/ecsanywhere:3",
"desiredCount": 1,
"pendingCount": 0,
"runningCount": 1,
"failedTasks": 0,
"createdAt": 1626101139.148,
"updatedAt": 1626101938.625,
"launchType": "EXTERNAL",
"rolloutState": "COMPLETED",
"rolloutStateReason": "ECS deployment ecs-svc/5388566575203796106 completed."
}
],
...
...
# - sed -i "s|{ecr_image}|${REPOSITORY_URI}:${IMAGE_TAG}|g" tf-any.json
# - LOCAL_ECS_CLUSTER="mydc-ecs-extcluster"
# - LOCAL_ECS_SERVICE="mydc-ecs-svc"
# - aws ecs register-task-definition --cli-input-json file://tf-any.json
# - LOCAL_TASK_DEFINITON="ecsanywhere"
# - LOCAL_TASK_REVISION=`aws ecs describe-task-definition --task-definition $LOCAL_TASK_DEFINITON | egrep "revision" | tr "/" " " | awk '{print $2}' | sed 's/,$//'`
# - aws ecs update-service --cluster $LOCAL_ECS_CLUSTER --service $LOCAL_ECS_SERVICE --task-definition $LOCAL_TASK_DEFINITON:${LOCAL_TASK_REVISION}
str = str.concat("<p style='text-align:center;font-family:Arial'>Version : 25 </p><br>\n");
service = ecs.CfnService(
self,
f"{props['ecsclustername']}-svc",
service_name=f"{props['ecsclustername']}-svc",
cluster=f"{props['ecsclustername']}-extcluster",
launch_type="EXTERNAL",
desired_count=2,
task_definition="ecsanywhere"
#task.to_string()
)
local_lb_security_group = ec2.SecurityGroup(
self,
"Load Balance internal Springboot http access",
vpc=vpc
)
local_lb_security_group.add_ingress_rule(
ec2.Peer.any_ipv4(),
ec2.Port.tcp(80)
)
local_lb_security_group.add_egress_rule(
ec2.Peer.ipv4(f"{props['mydcinternalcidr']}"),
ec2.Port.tcp(8080)
)
lb = elbv2.ApplicationLoadBalancer(
self,
"LB",
vpc=vpc,
internet_facing=True,
security_group=local_lb_security_group
)
listener = lb.add_listener(
"Listener",
port=80,
open=True
)
remotepi = elbv2.IpTarget(
f"{props['home-pi']}",
port=8080,
availability_zone="all")
listener.add_targets(
"Target",
port=8080,
targets=[remotepi]
)
cdk deploy ecs-anywhere-lb
ecs-anywhere-lb
ecs-anywhere-lb: deploying...
ecs-anywhere-lb: creating CloudFormation changeset...
✅ ecs-anywhere-lb
Outputs:
ecs-anywhere-lb.PiRemoteLB = ecs-a-LB8A1-UMQHFMJZEX80-435054691.eu-central-1.elb.amazonaws.com
Stack ARN:
arn:aws:cloudformation:eu-central-1:704533066374:stack/ecs-anywhere-lb/017fbe20-e3ca-11eb-b32e-06f34beb5820
Note! We only added one of the local nodes but we can add both which we will see in the next section.
cdk destroy ecs-anywhere-lb
sudo systemctl stop ecs
sudo systemctl status ecs
sudo systemctl start ecs
● ecs.service - Amazon Elastic Container Service - container agent
Loaded: loaded (/lib/systemd/system/ecs.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2021-06-28 12:37:53 UTC; 2 days ago
Docs: https://aws.amazon.com/documentation/ecs/
Main PID: 2214 (amazon-ecs-init)
Tasks: 8 (limit: 4435)
Memory: 12.0M
CGroup: /system.slice/ecs.service
└─2214 /usr/libexec/amazon-ecs-init start
level=critical time=2021-06-30T15:52:29Z msg="Data mismatch; saved cluster 'dc_pi_ecs_cluster' does not match configured cluster 'ecs-anywhere-ec2-mydcecsclusterBB109425-3HBnIv5IpvQm'. Perhaps you want to delete the configured checkpoint file?" module=agent.go
2021-06-30 18:30:37 ERROR Health ping failed with error - error occurred in RequestManagedInstanceRoleToken: AccessDeniedException: Authentication failed
status code: 400, request id: afbe8882-27ed-49fa-92a9-1c3582b12f11
cdk destroy ecs-anywhere-lb
cdk destroy ecs-anywhere-cfn
cdk destroy ecs-anywhere-pipe
cdk destroy ecs-anywhere-cicd
cdk destroy ecs-anywhere-vpc
sudo systemctl stop amazon-ssm-agent
sudo systemctl stop ecs
sudo apt remove amazon-ecs-init
sudo apt remove amazon-ssm-agent
sudo apt remove strongswan
39