Java Spring Boot X-Ray sidecar

Hi @michael
Do you have Java Spring Boot X-Ray sidecar example for cloudformation?
My colleague using “aws ecs” .json file. Im not sure how to translate that to “cloudformation” format.

Thank you
ateh

This is his “aws ecs task definition format” which after i converted from json to yml (https://www.json2yaml.com/). Im not sure how to add this to aws cloudformation format (java-spring-boot/template.yml).

---
executionRoleArn: arn:aws:iam::xx:role/xx
containerDefinitions:
- name: ph-cms
  image: "{{ECR_IMAGE}}"
  portMappings:
  - hostPort: 8080
    protocol: tcp
    containerPort: 8080
  - hostPort: 80
    protocol: tcp
    containerPort: 80
  logConfiguration:
    logDriver: awslogs
    options:
      awslogs-group: "/ecs/ph-cms-td"
      awslogs-region: ap-southeast-1
      awslogs-stream-prefix: ecs
  environment:
  - name: SPRING_PROFILES_ACTIVE
    value: awsdev
  essential: true
  cpu: 0
  memoryReservation: 500
  entryPoint: []
  volumesFrom: []
  mountPoints: []
- name: xray-sidecar
  image: amazon/aws-xray-daemon:latest
  portMappings:
  - protocol: udp
    containerPort: 2000
    hostPort: 2000
  logConfiguration:
    logDriver: awslogs
    options:
      awslogs-group: "/ecs/ph-cms-td"
      awslogs-region: ap-southeast-1
      awslogs-stream-prefix: ecs
  essential: true
  cpu: 0
  volumesFrom: []
  mountPoints: []
memory: '1024'
taskRoleArn: arn:aws:iam::xx:role/xx
requiresCompatibilities:
- FARGATE
networkMode: awsvpc
cpu: '512'

The way he execute his task in gitlab pipeline:

aws ecs register-task-definition --region ${AWS_REGION} --family ${TASK_DEFINITION} --cli-input-json file://.gitlab-deploy/task-def-with-xray.json

The relevant part is this:

AppService:
  Type: 'AWS::CloudFormation::Stack'
  Properties:
    Parameters:
      VpcModule: !GetAtt 'Vpc.Outputs.StackName'
      ClusterModule: !GetAtt 'Cluster.Outputs.StackName'
      TargetModule: !GetAtt 'AppTarget.Outputs.StackName'
      AlertingModule: !GetAtt 'Alerting.Outputs.StackName'
      ClientSgModule1: !GetAtt 'AuroraServerlessClientSg.Outputs.StackName'
      # TODO looks like you are not going to use the nginx proxy container, right?
      #ProxyImage: !Ref ProxyImage
      #ProxyPort: '80'
      AppImage: !Ref AppImage
      AppPort: '80' # TODO not sure if you want the load balancer to connect to port 80 or 8080, change accordingly.
      # I assume you don't need the database connection envs. If you need them, re-add them from the orig. example
      AppEnvironment1Key: 'SPRING_PROFILES_ACTIVE'
      AppEnvironment1Value: 'awsdev'
      SidecarImage: 'amazon/aws-xray-daemon:latest'
      SidecarPort: '2000' # TODO always TCP
      Cpu: '0.5'
      Memory: '1'
      DesiredCount: '2'
      MaxCapacity: '4'
      MinCapacity: '2'
      LogsRetentionInDays: '14'
      HealthCheckGracePeriodSeconds: '120'
    TemplateURL: './node_modules/@cfn-modules/fargate-service/module.yml'

The biggest issue I see is that we always assume a TCP as the port mapping protocol. If I understand your example, you need port 2000 for UDP, not TCP, right?

1 Like

Yes UDP. seem like it XRAY requirement

I see. I started the work to make the sidecar protocol configurable. You can track the progress here: https://github.com/cfn-modules/fargate-service/pull/32

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.