Environment Variables
You can use environment variables to configure which directory to install files in, where to store outputs, and how to store connection and logging settings. These settings are decoupled from the application logic, so you do not need to update your function code when you change the settings.
In the following code snippet, obs_output_bucket is the bucket used for storing processed images.
def handler(event, context):
srcBucket, srcObjName = getObsObjInfo4OBSTrigger(event)
obs_address = context.getUserData('obs_address')
outputBucket = context.getUserData('obs_output_bucket')
if obs_address is None:
obs_address = '{obs_address_ip}'
if outputBucket is None:
outputBucket = 'casebucket-out'
ak = context.getAccessKey()
sk = context.getSecretKey()
# download file uploaded by user from obs
GetObject(obs_address, srcBucket, srcObjName, ak, sk)
outFile = watermark_image(srcObjName)
# Upload converted files to a new OBS bucket.
PostObject (obs_address, outputBucket, outFile, ak, sk)
return 'OK'
Using environment variable obs_output_bucket, you can flexibly set the OBS bucket used for storing output images.
Configuring Environment Variables
- Log in to the FunctionGraph console. In the navigation pane, choose Functions > Function List.
- Click the name of the function to be configured. The function details page is displayed.
- Choose Configuration > Environment Variables and click Edit Environment Variable.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot