Created
February 13, 2024 19:20
-
-
Save mjzone/b383117816fcb942c1c65c88229c9a65 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import https from 'https'; | |
// Function to make an HTTPS GET request | |
const makeGetRequest = async () => { | |
return new Promise((resolve, reject) => { | |
const options = { | |
hostname: '<prefix>.execute-api.<region>.amazonaws.com', | |
path: '/dev/pets', | |
method: 'GET', | |
}; | |
const req = https.request(options, (res) => { | |
let data = ''; | |
// A chunk of data has been received. | |
res.on('data', (chunk) => { | |
data += chunk; | |
}); | |
// The whole response has been received. | |
res.on('end', () => { | |
resolve(data); | |
}); | |
}); | |
req.on('error', (e) => { | |
reject(e); | |
}); | |
// End the request | |
req.end(); | |
}); | |
}; | |
// Main Lambda handler | |
export const handler = async (event) => { | |
try { | |
const response = await makeGetRequest(); | |
console.log('Response:', response); | |
return { | |
statusCode: 200, | |
body: JSON.stringify({ | |
message: 'Request successful', | |
data: response, | |
}), | |
}; | |
} catch (error) { | |
console.error('Error:', error); | |
return { | |
statusCode: 500, | |
body: JSON.stringify({ | |
message: 'Request failed', | |
error: error.message, | |
}), | |
}; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment