1

How to add "Overwrite the content" in codedeploy via cloudformation template

I template is fine and running but when i'm trying to deploy new version it's giving me different errors.

Such as below

  • The deployment failed because a specified file already exists at this location. I did deleted the whole folder.
  • Script at specified location: scripts/app_stop.sh run as user root failed with exit code 1

LifecycleEvent - ApplicationStop Script - scripts/app_stop.sh [stderr]Unknown operation 'httpd'.

I have the httpd up and running.

Edit- I have specified "IgnoreApplicationStopFailures: true" already in my DeploymentGroup Resources section.

Edit- My app_stop.sh looks like below -

if [ -d /var/www/html/scripts ]; then
    sudo rm -Rf /var/www/html/* /opt/codedeploy-agent/deployment-root/*
fi
isExistApp=`pgrep httpd`
if [[ -n  $isExistApp ]]; then
    sudo systemctl stop httpd         
fi

Edit - Added the template to be changed.

Group:
    Type: AWS::CodeDeploy::DeploymentGroup
    Properties:
      ApplicationName: !ImportValue DeployName
      Deployment:
        IgnoreApplicationStopFailures: true
        Description: 'Code Deploy to Train'  
        Revision:
          RevisionType: S3
          S3Location:
            Bucket: '<sample>'
            BundleType: 'zip'
            Key: '<test>.zip'   
      Ec2TagFilters:
        -
          Key: 'Type'
          Value: 'Train'
          Type: 'KEY_AND_VALUE'
      ServiceRoleArn: !GetAtt [PipeRole, Arn]

I would be needing the to use the below options with the Overwrite feature alongside this template.

AWS CodeDeploy Additional Options

  • Can you be more specific? Can you show your template and explain what's wrong with it or how you want to change it? – Marcin Aug 26 '21 at 03:16
  • Hello @Marcin, I have added the requested details to the question, apologies for not adding it earlier. – Shourya Sharma Aug 26 '21 at 03:47
  • Sorry, but its still not clear. What do you mean by " Overwrite feature" or ""Overwrite the content""? Which content? Overwrite how? – Marcin Aug 26 '21 at 03:59
  • Okay i suppose this issue is addresses in below question. https://stackoverflow.com/questions/54587693/codedeploy-configuration-to-overwrite-files And it is resolved, I need to add according to the below link to overwrite the files present already in the folder. https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-files.html Thanks a lot for your help @Marcin – Shourya Sharma Aug 26 '21 at 04:05
  • If the issue is solved, you can answer your own question with extra details. You can also accept your own answer. – Marcin Aug 26 '21 at 04:38
  • Okay will do thanks again.. – Shourya Sharma Aug 26 '21 at 05:06

1 Answers1

1

For quick reference here's the solution mentioned in the comments above.

Now you can specify file_exists_behavior in your appspec file. Allowed values are DISALLOW, OVERWRITE, or RETAIN.

version: 0.0
    os: linux
    files:
      - source: /
        destination: /home/ubuntu/site
    file_exists_behavior: OVERWRITE
phpd
  • 551
  • 4
  • 10