This sample application demonstrates how to retrieve metadata when running in Google App Engine Flexible Environment.
For detailed steps to deploy this app, you can follow the Google Cloud documentation, but use the Metadata project instead of the HelloWorld project.