Configuring environment variables for Extend App
The Extend Override and Events Handler are in Open Beta for AGS Premium Clients! This means Extend available for you to try on your development environment. You can submit your feedback through this link.
Overview
In AccelByte Gaming Services (AGS), the endpoint can be extended by "plugging-in" the own custom functions. To do this, we need to create a gRPC Server, with a specific proto file that contains the implementation of the custom functions. Then we can configure AGS to invoke these custom functions in the gRPC Server, instead of the default functions.
The gRPC server itself will have some default Environment Secret Configuration and Environment Variable Configuration value as shown in the image below.
In this guide, we will explain how to customize the environments. We can add, update, or delete both of the Environment Secret Configuration and Environment Variable Configuration.
How to Customize the Environment Secret Configuration
Add a new environment secret configuration
- In the code, create a new function to call the environment secret according to the need. For example, add secret NEW_SECRET_URL as shown below:
- Golang
- Python
func main() {
...
logrus.Infof("gRPC server started")
logrus.Infof("app server started")
_ = newFunctionHere() // call the function here
}
func newFunctionHere() error {
// we can use existing GetEnv() function from this repo, or use native golang function os.GetEnv()
logrus.Printf("New secret variable: %s", server.GetEnv("NEW_SECRET_URL", "www.secreturlfallback.com"))
return nil
}
async def main(port: int, profanities_file: Optional[str] = None, **kwargs) -> None:
env = Env(
eager=kwargs.get("env_eager", True),
expand_vars=kwargs.get("env_expand_vars", False),
)
new_function_here(env)
...
await App(port, env, opts=opts).run()
def new_function_here(env):
print('New secret variable: ' + env("NEW_SECRET_URL", "www.secreturlfallback.com"))
def parse_args():
...
return result
if __name__ == "__main__":
asyncio.run(main(**parse_args()))
If docker-compose is used, add the new variable NEW_SECRET_URL in the docker-compose.yaml file under the environment: section.
services:
app:
build:
...
environment:
...
- NEW_SECRET_URL
Re-deploy the gRPC server latest image to the cluster. Make sure the code is updated.
Click Add Secret button to add NEW_SECRET_URL as key, and it's value. Then click Add button.
After successfully added, finish it by clicking the Restart and Apply button on the right side of the page.
Last, check if the gRPC server is calling the right value.
Update an existing environment secret configuration
Click edit icon on the left side of the secret value, adjust the value according to the need, then click Save.
After successfully updated, finish it by clicking the Restart and Apply button on the right side of the page.
Delete an existing environment secret configuration
Click delete icon on the left side of the secret value, there will be confirmation, then click the Delete red button.
After successfully deleted, finish it by clicking the Restart and Apply button on the right side of the page.
How to Customize the Environment Variable Configuration
Add a new environment variable configuration
- In the code, create a new function to call the environment variable according to the need. For example, add environment variable NEW_ENVAR_URL as shown below:
- Golang
- Python
func main() {
...
logrus.Infof("gRPC server started")
logrus.Infof("app server started")
_ = anotherNewFunctionHere() // call the function here
}
func anotherNewFunctionHere() error {
// we can use existing GetEnv() function from this repo, or use native golang function os.GetEnv()
logrus.Printf("New environment variable: %s", server.GetEnv("NEW_ENVAR_URL", "www.envarurlfallback.com"))
return nil
}
async def main(port: int, profanities_file: Optional[str] = None, **kwargs) -> None:
env = Env(
eager=kwargs.get("env_eager", True),
expand_vars=kwargs.get("env_expand_vars", False),
)
another_new_function_here(env)
...
await App(port, env, opts=opts).run()
def another_new_function_here(env):
print('New environment variable: ' + env("NEW_ENVAR_URL", "www.envarurlfallback.com"))
def parse_args():
...
return result
if __name__ == "__main__":
asyncio.run(main(**parse_args()))
If docker-compose is used, add the new variable NEW_ENVAR_URL in the docker-compose.yaml file under the environment: section.
services:
app:
build:
...
environment:
...
- NEW_ENVAR_URL
Re-deploy the gRPC server latest image to the cluster. Make sure the code is updated.
Click Add Variable button to add NEW_ENVAR_URL as key, and it's value. Then click Add button.
After successfully added, finish it by clicking the Restart and Apply button on the right side of the page.
Last, check if the gRPC server is calling the right value.
Update an existing environment variable configuration
Click edit icon on the left side of the variable value, adjust the value, then click Save.
After successfully updated, finish it by clicking the Restart and Apply button on the right side of the page.
Delete an existing environment variable configuration
Click delete icon on the left side of the variable value, there will be confirmation, then click the Delete red button.
After successfully deleted, finish it by clicking the Restart and Apply button on the right side of the page.