Skip to content

Commit 43777af

Browse files
Add aws retry attempts (#19)
* Adding an input var to accept max retry attempts * removed $ * Updated readme * Update push-to-s3-and-invalidate-cloudfront/README.md Co-authored-by: Alberto Fumagalli <[email protected]> * Update push-to-s3-and-invalidate-cloudfront/README.md Co-authored-by: Alberto Fumagalli <[email protected]> Co-authored-by: Alberto Fumagalli <[email protected]>
1 parent a931277 commit 43777af

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

push-to-s3-and-invalidate-cloudfront/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Files are pushed to the S3 bucket depending on the user inputs supplied when the
66
Following examples describe how to use the action.
77

88
## Uploading to S3 based on user input
9-
This example will **upload** the specified folder (`build-directory`) to a folder named `blog` on the S3 bucket(`myS3Bucket`). The action will not exclude any files while uploading them. The action will also invalidate the cloudfront cache.
9+
This example will **upload** the specified folder (`build-directory`) to a folder named `blog` on the S3 bucket(`myS3Bucket`). The action will not exclude any files while uploading them. The action will also invalidate the cloudfront cache. The action will attempt a max of `5` (based on `aws-retry-attempts` value) retries for any AWS operations before erroring out.
1010

1111
```yaml
1212
- uses: XanaduAI/cloud-actions/push-to-s3-and-invalidate-cloudfront@main
@@ -22,10 +22,12 @@ This example will **upload** the specified folder (`build-directory`) to a folde
2222
s3-dir-to-upload-to: "blog"
2323
s3-files-to-exclude: ""
2424
invalidate-cloudfront-cache: "true"
25+
aws-retry-attempts: 5
2526
```
2627
2728
## Deleting from S3 based on user input
28-
This example will **delete** the specified folder (`build-directory`) from the S3 bucket(`myS3Bucket`). The action will also invalidate the cloudfront cache.
29+
This example will **delete** the specified folder (`build-directory`) from the S3 bucket(`myS3Bucket`). The action will also invalidate the cloudfront cache. The action will attempt a max of `5` (based on `aws-retry-attempts` value) retries for any AWS operations before erroring out.
30+
2931

3032
```yaml
3133
- uses: XanaduAI/cloud-actions/push-to-s3-and-invalidate-cloudfront@main
@@ -40,12 +42,14 @@ This example will **delete** the specified folder (`build-directory`) from the S
4042
s3-action: "delete"
4143
s3-dir-to-delete-from: "blog"
4244
invalidate-cloudfront-cache: "true"
45+
aws-retry-attempts: 5
4346
```
4447

4548
## Uploading/Deleting to/from S3 with minimal user unput
4649
If this action is called when a `pull_request` is `opened` or `syncronized`, then the example will **upload** the specified folder (`build-directory`) to a folder named `pr-previews/PR-123` on the S3 bucket (`myS3Bucket`). The action will exclude any files that start with the default `pr-previews` prefix. The action will not invalidate the cloudfront cache.
4750

4851
If this action is called when a `pull_request` is `closed`, then the example will **delete** the folder named `pr-previews/PR-123` on the S3 bucket (`myS3Bucket`).
52+
The action will attempt a max of `2` (default) retries for any AWS operations before erroring out.
4953

5054
```yaml
5155
- uses: XanaduAI/cloud-actions/push-to-s3-and-invalidate-cloudfront@main

push-to-s3-and-invalidate-cloudfront/action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ inputs:
5050
description: A flag to indicate if the cloudfront cache should be invalidated
5151
required: false
5252
default: "false"
53+
aws-retry-attempts:
54+
description: |
55+
The number of retries to perform an AWS action. If unspecified will default to 2 retires.
56+
Refer to https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-retries.html for the usage of retry retry attempts
57+
required: false
58+
default: "2"
5359

5460
outputs:
5561
dir_name:
@@ -110,6 +116,7 @@ runs:
110116
AWS_REGION: ${{ inputs.aws-region }}
111117
AWS_ACCESS_KEY_ID: ${{ inputs.aws-access-key-id }}
112118
AWS_SECRET_ACCESS_KEY: ${{ inputs.aws-secret-access-key }}
119+
AWS_MAX_ATTEMPTS: ${{ inputs.aws-retry-attempts }}
113120
run: |
114121
aws s3 sync ${{ inputs.build-directory }}/ s3://${{ inputs.s3-bucket }}/${{ steps.directory.outputs.dir_name }} ${{ steps.exclude.outputs.files_to_exlude }}
115122
@@ -120,6 +127,7 @@ runs:
120127
AWS_REGION: ${{ inputs.aws-region }}
121128
AWS_ACCESS_KEY_ID: ${{ inputs.aws-access-key-id }}
122129
AWS_SECRET_ACCESS_KEY: ${{ inputs.aws-secret-access-key }}
130+
AWS_MAX_ATTEMPTS: ${{ inputs.aws-retry-attempts }}
123131
run: aws s3 rm s3://${{ inputs.s3-bucket }}/${{ steps.directory.outputs.dir_name }}/ --recursive ${{ steps.exclude.outputs.files_to_exlude }}
124132

125133
- name: Invalidate the cloudfront cache
@@ -129,5 +137,6 @@ runs:
129137
AWS_REGION: ${{ inputs.aws-region }}
130138
AWS_ACCESS_KEY_ID: ${{ inputs.aws-access-key-id }}
131139
AWS_SECRET_ACCESS_KEY: ${{ inputs.aws-secret-access-key }}
140+
AWS_MAX_ATTEMPTS: ${{ inputs.aws-retry-attempts }}
132141
run: |
133142
aws cloudfront create-invalidation --distribution-id ${{ inputs.aws-cloudfront-distribution-id }} --paths "/${{ steps.directory.outputs.dir_name }}/*"

0 commit comments

Comments
 (0)