s3-publish-files 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. #
  3. # s3-publish-files - Deploy files to S3
  4. #
  5. # usage: s3-publish-files src dst distribution-id aws-profile
  6. #
  7. SRC=$1
  8. DST=$2
  9. DISTRIBUTION=$3
  10. AWS_PROFILE=$4
  11. if [ "${SRC}" = "" ] ; then
  12. echo "SRC is not provided"
  13. exit 255
  14. fi
  15. if [ "${DST}" = "" ] ; then
  16. echo "DST is not provided"
  17. exit 255
  18. fi
  19. if [ "${AWS_PROFILE}" = "" ] ; then
  20. export AWS_ACCESS_KEY_ID=${PUBLISH_KEYS_AWS_ACCESS}
  21. export AWS_SECRET_ACCESS_KEY=${PUBLISH_KEYS_AWS_SECRET}
  22. export AWS_DEFAULT_REGION=${PUBLISH_KEYS_AWS_REGION}
  23. export AWS_DEFAULT_PROFILE=${PUBLISH_KEYS_AWS_PROFILE}
  24. if [ "${AWS_ACCESS_KEY_ID}" = "" ] ; then
  25. echo "PUBLISH_KEYS_AWS_ACCESS is not defined"
  26. exit 255
  27. fi
  28. fi
  29. . $(dirname ${BASH_SOURCE[0]})/common
  30. echo aws s3 sync --no-progress ${SRC} "s3://${DST}/" --delete --profile "${AWS_PROFILE}"
  31. aws s3 sync --no-progress ${SRC} "s3://${DST}/" --delete --profile "${AWS_PROFILE}"
  32. if [ $? != 0 ] ; then
  33. echo "Cannot copy to S3"
  34. exit 255
  35. fi
  36. echo aws cloudfront create-invalidation --distribution-id ${DISTRIBUTION} --paths '/*' --profile "${AWS_PROFILE}"
  37. aws configure set preview.cloudfront true
  38. aws cloudfront create-invalidation --distribution-id ${DISTRIBUTION} --paths '/*' --profile "${AWS_PROFILE}"
  39. if [ $? != 0 ] ; then
  40. echo "Cannot create invalidation for distribution ${DISTRIBUTION} profile ${AWS_PROFILE}"
  41. exit 255
  42. fi
  43. exit 0