Skip to content

Commit ed4b015

Browse files
authored
Downgrade TriggerFunction node to v14 because 18 is not available in all regions (#2948)
1 parent 2a4f467 commit ed4b015

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

integration/resources/templates/combination/connector_appsync_to_table.yaml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,11 @@ Resources:
8080
Variables:
8181
API_KEY: !GetAtt ApiKey.ApiKey
8282
GRAPHQL_URL: !GetAtt AppSyncApi.GraphQLUrl
83-
Runtime: nodejs18.x
83+
Runtime: nodejs14.x
8484
Handler: index.handler
8585
InlineCode: |
86+
const https = require("https");
87+
8688
exports.handler = async (_) => {
8789
const queries = {
8890
getNote: /* GraphQL */ `
@@ -103,23 +105,47 @@ Resources:
103105
`,
104106
};
105107
108+
const fetch = async (url, options) =>
109+
new Promise((resolve, reject) => {
110+
const req = https.request(url, options, (res) => {
111+
const body = [];
112+
res.on("data", (chunk) => body.push(chunk));
113+
res.on("end", () => {
114+
const resString = Buffer.concat(body).toString();
115+
resolve(resString);
116+
});
117+
});
118+
119+
req.on("error", (err) => {
120+
reject(err);
121+
});
122+
123+
req.on("timeout", () => {
124+
req.destroy();
125+
reject(new Error("Request time out"));
126+
});
127+
128+
req.write(options.body);
129+
req.end();
130+
});
131+
106132
const makeRequest = async (queryName) => {
107133
const options = {
108134
method: "POST",
109135
headers: {
110136
"x-api-key": process.env.API_KEY,
111137
},
112138
body: JSON.stringify({ query: queries[queryName] }),
139+
timeout: 10000, // ms
113140
};
114141
115142
let statusCode;
116143
let body;
117144
let response;
118145
119146
try {
120-
/*global fetch*/
121147
response = await fetch(process.env.GRAPHQL_URL, options);
122-
body = await response.json();
148+
body = JSON.parse(response);
123149
const data = body.data?.[queryName];
124150
const hasNoErrors = body.errors === undefined;
125151
const allFieldsAreSet =
@@ -172,5 +198,6 @@ Resources:
172198
};
173199
};
174200
201+
175202
Metadata:
176203
SamTransformTest: true

0 commit comments

Comments
 (0)