Skip to content

Commit 5d3e5bd

Browse files
authored
Retry storage upload/download in e2e lambda (#1098)
1 parent 318335d commit 5d3e5bd

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

.changeset/shy-horses-act.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

packages/integration-tests/src/test-projects/data-storage-auth-with-triggers-ts/amplify/func-src/response_generator.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,35 @@ export const getResponse = async () => {
5353
*/
5454
const s3RoundTrip = async (): Promise<string> => {
5555
const filename = 'test.txt';
56-
await uploadData({
57-
key: filename,
58-
data: 'this is some test content',
59-
options: {
60-
accessLevel: 'guest',
61-
},
62-
}).result;
56+
await retry(
57+
() =>
58+
uploadData({
59+
key: filename,
60+
data: 'this is some test content',
61+
options: {
62+
accessLevel: 'guest',
63+
},
64+
}).result
65+
);
6366

64-
const downloadResult = await downloadData({
65-
key: filename,
66-
options: { accessLevel: 'guest' },
67-
}).result;
67+
const downloadResult = await retry(
68+
() =>
69+
downloadData({
70+
key: filename,
71+
options: { accessLevel: 'guest' },
72+
}).result
73+
);
6874
return downloadResult.body.text() as Promise<string>;
6975
};
76+
77+
// executes action and if it throws, executes the action again after a second
78+
// if the action fails a second time, the error is re-thrown
79+
const retry = async <T>(action: () => Promise<T>) => {
80+
try {
81+
return action();
82+
} catch (err) {
83+
console.log(err);
84+
await new Promise((resolve) => setTimeout(resolve, 1000));
85+
return action();
86+
}
87+
};

0 commit comments

Comments
 (0)