0

When i run App.spec file for aws ECS blue green deployment the error is coming : "The deployment failed because the AppSpec file that specifies the deployment configuration is missing or has an invalid configuration. Failed to parse your appspec file. Please validate your appspec format and try again later." If anyone knows about this error. Please let me know me.

  • Please provide enough code so others can better understand or reproduce the problem. – 70ny Oct 21 '22 at 16:11

1 Answers1

0

Validate your AppSpec File

File syntax Validation:

you can use a browser-based tool such as YAML lint http://www.yamllint.com or an Online YAML parser http://yaml-online-parser.appspot.com to help you check your YAML syntax. Most of the time, it would solve your problem.

File Location validation:

Make sure to name your AppSpec File as appspec.yml, To verify that you have placed your AppSpec file in the root directory of the application's source content's directory structure, run one of the following commands:

On local Linux, macOS, or Unix instances:

ls path/to/root/directory/appspec.yml

If the AppSpec file is not located there, a "No such file or directory" error is displayed.

On local Windows instances:

dir path\to\root\directory\appspec.yml

If the AppSpec file is not located there, a "File Not Found" error is displayed.

AppSpec File example for an Amazon ECS deployment

Following is an example of an AppSpec file written in YAML for deploying an Amazon ECS service.

version: 0.0
Resources:
  - TargetService:
      Type: AWS::ECS::Service
      Properties:
        TaskDefinition: "arn:aws:ecs:us-east-1:111222333444:task-definition/my-task-definition-family-name:1"
        LoadBalancerInfo:
          ContainerName: "SampleApplicationName"
          ContainerPort: 80
# Optional properties
        PlatformVersion: "LATEST"
        NetworkConfiguration:
          AwsvpcConfiguration:
            Subnets: ["subnet-1234abcd","subnet-5678abcd"]
            SecurityGroups: ["sg-12345678"]
            AssignPublicIp: "ENABLED"
        CapacityProviderStrategy:
          - Base: 1
            CapacityProvider: "FARGATE_SPOT"
            Weight: 2
          - Base: 0
            CapacityProvider: "FARGATE"
            Weight: 1
Hooks:
  - BeforeInstall: "LambdaFunctionToValidateBeforeInstall"
  - AfterInstall: "LambdaFunctionToValidateAfterInstall"
  - AfterAllowTestTraffic: "LambdaFunctionToValidateAfterTestTrafficStarts"
  - BeforeAllowTraffic: "LambdaFunctionToValidateBeforeAllowingProductionTraffic"
  - AfterAllowTraffic: "LambdaFunctionToValidateAfterAllowingProductionTraffic"

AppSpec File example for an Amazon EC2 deployment

See the hooks, which hooks are available and used to do what for a successful deployment.

version: 0.0
os: linux
files:
  - source: /
    destination: /var/www/html
file_exists_behavior: OVERWRITE
permissions:
  - object: /var/www/html
    pattern: "**"
    owner: root
    group: www-data
    mode: 644 # gives read and write permissions to the owner of the object (6), read-only permissions to the group (4), and read-only permissions to all other users (4).
    # acls: 
    #   - u:deployer:rwx
    type:
      - file
  - object: /var/www/html
    pattern: "**"
    owner: root
    group: www-data
    mode: 755 # sets the setuid attribute (4), gives full control permissions to the owner (7), gives read and execute permissions to the group (5), and gives read and execute permissions to all other users (5).
    # acls: 
    #   - u:deployer:rwx
    type:
      - directory
hooks:
  BeforeBlockTraffic: # run tasks on instances before they are deregistered from a load balancer.
    - location: ./devops/hooks/1_BeforeBlockTraffic.sh
      timeout: 300
      runas: deployer # we are running codedeploy as non-root user and only the root user has the ability to have runas "su" command without password authentication
  # BlockTraffic: # can't be scripted
  #   - location: ./devops/hooks/2_BlockTraffic.sh
  #     timeout: 300
  #     # runas: deployer
  AfterBlockTraffic: # run tasks on instances after they are deregistered from a load balancer.
    - location: ./devops/hooks/3_AfterBlockTraffic.sh
      timeout: 300
      runas: deployer
  ApplicationStop: # occurs even before the application revision is downloaded
    - location: ./devops/hooks/4_ApplicationStop.sh
      timeout: 300
      runas: root
  # DownloadBundle: # can't be scripted
  #   - location: ./devops/hooks/5_DownloadBundle.sh
  #     timeout: 300
  #     runas: deployer
  BeforeInstall:
    - location: ./devops/hooks/6_BeforeInstall.sh
      timeout: 300
      runas: root
  # Install: # can't be scripted, copies the revision files from the temporary location to the final destination folder. 
  #   - location: ./devops/hooks/7_Install.sh
  #     timeout: 300
  #     runas: deployer
  AfterInstall:
    - location: ./devops/hooks/8_AfterInstall.sh
      timeout: 300
      # runas: deployer
  ApplicationStart:
    - location: ./devops/hooks/9_ApplicationStart.sh
      timeout: 300
      runas: root
  ValidateService:
    - location: ./devops/hooks/10_ValidateService.sh
      timeout: 300
      runas: deployer
  BeforeAllowTraffic: # run tasks on instances before they are registered with a load balancer.
    - location: ./devops/hooks/11_BeforeAllowTraffic.sh
      timeout: 300
      # runas: deployer
  # AllowTraffic: # can't be scripted
  #   - location: ./devops/hooks/12_AllowTraffic.sh
  #     timeout: 300
  #     # runas: deployer
  AfterAllowTraffic: # run tasks on instances after they are registered with a load balancer.
    - location: ./devops/hooks/13_AfterAllowTraffic.sh
      timeout: 300
      # runas: deployer
Zeeshan
  • 357
  • 1
  • 8