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 obsGetObject(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.
Figure 1 Setting an environment variable

Parent topic: Advanced Operations