amplify-hosting icon indicating copy to clipboard operation
amplify-hosting copied to clipboard

Post Deploy Phase!

Open avner-hoffmann opened this issue 4 years ago • 9 comments

Is your feature request related to a problem? Please describe. One thing that is very much missing from amplify is a "post deploy" phase in which one can write scripts or perform operations after the full CI CD process succeeds. e.g. run a script which creates a github release for the just deployed release.

Describe the solution you'd like Add a post deployment phase to make amplify more customizable

avner-hoffmann avatar Apr 14 '20 14:04 avner-hoffmann

@avner-hoffmann I'll let our product manager know about your suggestion.

One question: Would a notification work just as well? Similar to our build notifications?

adriencg avatar Apr 14 '20 17:04 adriencg

@adriencg - I'm not sure I understood the question. Are you asking if amplify will need to provide another notification as for the success or failure of the post deploy phase ?

avner-hoffmann avatar Apr 21 '20 07:04 avner-hoffmann

@adriencg is the postBuild phase when the 'Deploy' phase completes? @avner-hoffmann I think this might be the time to run post-deployment scripts (docs: https://docs.aws.amazon.com/amplify/latest/userguide/build-settings.html).

jasonrundell avatar Jun 10 '21 01:06 jasonrundell

+1, REALLY IMPORTANT to be able to clean custom CDN and to have an hook for post-build operations

iceye avatar Aug 23 '21 22:08 iceye

+1, the postBuild step will run before tests, and run before the actual successful deploy happens so if any of those steps fail, I've still incorrectly ran a postBuild command that I only wanted to run after the deploy step.

sealabcore avatar Mar 10 '22 15:03 sealabcore

+1 to allowing postDeploy configuration. I find the lack of hooks b/w the various phases very limiting but adding post deploy support would be a good start.

hinaaman avatar May 10 '22 23:05 hinaaman

+1 postDeploy step would be really helpful for developers run post deployment scripts(e.g. to send release emails) after actual deployment, currently thats only possible at the postBuild stage which runs before the deployment.

yohan-aloka avatar Jul 26 '22 03:07 yohan-aloka

+1 Pleeeeese, we need this feature

woolimi avatar Jul 28 '22 13:07 woolimi

@woolimi Hey :) It's probably going to take them a long time, so a workaround (although not very simple) is to use something like GitHub actions to run the Amplify build and then when it completes to run your task or suite of tasks after it completes.

jasonrundell avatar Jul 28 '22 14:07 jasonrundell

+1 postDeploy step, in our case we need to invalidate other caches after the deploy. I've seen workarounds configuring alerts and checking the email that arrives there... Maybe too complex in my opinion

fnavarrodev avatar Dec 13 '22 10:12 fnavarrodev

+1, may help us a lot!

RLeDEV avatar Feb 07 '23 17:02 RLeDEV

Would love to have this functionality so that we can smoke test preview environments after they've been deployed.

yhakbar avatar May 08 '23 19:05 yhakbar

+1

jaybrueder avatar Jun 01 '23 09:06 jaybrueder

+1, this is super important for us where we need the ability to interact with deployed site immediately after deployment in a programmatic way. (specifically, send POST requests to the underlying webserver that will be listening once deployed)

@jasonrundell did you have any specifics you would be able to provide? With github actions, how could the action be 100% sure that the amplify deploy process has actually completed? Sure it can schedule a job to start the deploy, but the deployment takes some amount of time, and we would need to know it has complete fully before running our next task.

ia-jortega avatar Sep 18 '23 14:09 ia-jortega

+1, this is super important for us where we need the ability to interact with deployed site immediately after deployment in a programmatic way. (specifically, send POST requests to the underlying webserver that will be listening once deployed)

@jasonrundell did you have any specifics you would be able to provide? With github actions, how could the action be 100% sure that the amplify deploy process has actually completed? Sure it can schedule a job to start the deploy, but the deployment takes some amount of time, and we would need to know it has complete fully before running our next task.

@ia-jortega and action like this could be what you're after:

name: My CI/CD Workflow

on:
  push:
    branches:
      - main

jobs:
  amplify_build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Run AWS Amplify Build
        run: |
          # Your AWS Amplify build commands go here
          # For example:
          # amplify init
          # amplify push

  next_job:
    runs-on: ubuntu-latest
    needs: amplify_build # This job depends on the "amplify_build" job
    if: success() # This job will run only if "amplify_build" succeeds
    steps:
      - name: Run subsequent steps
        run: |
          # Your next steps go here

jasonrundell avatar Sep 18 '23 15:09 jasonrundell

@jasonrundell Thank you fellow Jason, this looks promising. Before any research in the docs, it seems like the key here is the "needs" and "if" directive.

It almost reminds me of AWS Cloudformation where the "DependsOn" Directive is used for order of operations for resources dfined in one template .yml.

Will update if this works for us!

ia-jortega avatar Sep 18 '23 15:09 ia-jortega

@jasonrundell This indeed seems to be a great way to solve the issue! I can see why people are having trouble finding this because it feels as if we should be trying to know about Amplify status using github action constructs, but in fact we still must use aws amplify to actually know about the status of the build/deployment job.

I cant find the SO post I got the bulk of this idea from but this is the final bash script I run in the github action that checks the amplify build status to make sure its actually done deploying b4 the next step starts:

`#!/bin/bash

echo "Deploy app $aws_app_id branch $branch_name"

JOB_ID=$(aws amplify start-job --app-id $aws_app_id --branch-name $branch_name --job-type RELEASE --query 'jobSummary.jobId' --output text)

echo "Release started" echo "Job ID is $JOB_ID"

while [[ "$(aws amplify get-job --app-id $aws_app_id --branch-name $branch_name --job-id $JOB_ID --query 'job.summary.status' --output text)" =~ ^(PENDING|RUNNING)$ ]]; do sleep 1; done

JOB_STATUS="$(aws amplify get-job --app-id $aws_app_id --branch-name $branch_name --job-id $JOB_ID --query 'job.summary.status' --output text)" echo "Job finished" echo "Job status is $JOB_STATUS" `

ia-jortega avatar Sep 19 '23 23:09 ia-jortega