Created
June 27, 2021 14:29
-
-
Save leegilmorecode/ed2c23a95a36f10ccdeb6ca1d90246a0 to your computer and use it in GitHub Desktop.
Example of a lambda handler using the AWS AppConfig Lambda Layer Extension.
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
/* eslint-disable no-undef */ | |
const axios = require("axios"); | |
const { | |
STAGE: stage, | |
APPLICATION: application, | |
ENVIRONMENT: environment, | |
CONFIGURATION: configuration, | |
} = process.env; | |
exports.feature = async () => { | |
const url = `http://localhost:2772/applications/${application}/environments/${environment}/configurations/${configuration}`; | |
console.log(`app config endpoint: ${url}`); | |
console.log(`stage: ${stage}`); | |
try { | |
const config = await axios.get(url); | |
const { featureEnabled = false } = config.data; | |
// use this to enable/disable your feature | |
const response = { | |
statusCode: 200, | |
body: `You have ${featureEnabled ? "enabled" : "disabled"} feature`, | |
}; | |
return response; | |
} catch (error) { | |
console.error(error); | |
const response = { | |
statusCode: 500, | |
body: `message: ${error.message}`, | |
}; | |
return response; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment