QuestionQ358

Deploying applications

You want to create fully baked, or golden, Compute Engine images for your application. You need to bootstrap the application so that it connects to the appropriate database for the environment in which it runs (test, staging, production). What should you do?

  • A Embed the appropriate database connection string in the image. Create a different image for each environment.
  • B When creating the Compute Engine instance, add a tag with the name of the database to be connected. In your application, query the Compute Engine API to pull the tags for the current instance, and use the tag to construct the appropriate database connection string.
  • C When creating the Compute Engine instance, create a metadata item with a key of ג€DATABASEג€ and a value for the appropriate database connection string. In your application, read the ג€DATABASEג€ environment variable, and use the value to connect to the appropriate database.
  • D When creating the Compute Engine instance, create a metadata item with a key of ג€DATABASEג€ and a value for the appropriate database connection string. In your application, query the metadata server for the ג€DATABASEג€ value, and use the value to connect to the appropriate database.
Explanation

Compute Engine custom instance metadata can hold environment-specific key-value configuration when a VM is created. An application running on that VM can query the metadata server to retrieve the custom DATABASE value, allowing the same golden image to be used across test, staging, and production without embedding a different connection string in each image.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!