Consuming Service Dependencies¶
When you specify a dependency on a service using Service Dependencies, that service is auto-wired to your application. This page contains information about how you can consume those injected dependencies in your application code to actually communicate with these services.
When Handel wires services together securely, it will inject environment variables into the consuming service for each service that it depends on. These environment variables provide information about the created service that tell you information such as where to find the service and how to communicate with it.
The following Handel file defines a Beanstalk service that depends on an SQS queue:
version: 1 name: beanstalk-example environments: dev: webapp: type: beanstalk path_to_code: . solution_stack: 64bit Amazon Linux 2016.09 v4.0.1 running Node.js instance_type: t2.micro health_check_url: / min_instances: 1 max_instances: 1 dependencies: - my-queue my-queue: type: sqs
Handel will inject environment variables in the Beanstalk application for the SQS queue, such as the queue’s ARN, name, and URL. You can read these environment variables when you are writing code to communicate with the queue.
Environment Variable Names¶
Every environment variable injected by Handel for service dependencies has a common structure.
This environment variable name consists of the dependency’s name (as defined in the Handel file), followed by the name of the value being injected.
In the above example, the referencing Beanstalk application would need to use the following name to get the URL of the SQS Queue:
All Handel injected environment variables will be all upper-cased, with dashes converted to underscores.
Parameter Store Prefix¶
Handel puts auto-generated credentials and other secrets in the EC2 Parameter Store, and it wires up your applications to allow you to access these secrets.
Each parameter Handel puts in the parameter store has a common prefix, which is defined by the following structure:
You can use the Common Injected Environment Variables to obtain the value of this prefix.
Common Injected Environment Variables¶
In addition to environment variables injected by services your applications consume, Handel will inject a common set of environment variables to all applications:
|HANDEL_APP_NAME||This is the value of the name field from your Handel file. It is the name of your application.|
|HANDEL_ENVIRONMENT_NAME||This is the value of the <environment> field from your Handel file. It is the name of the environment the current service is a part of.|
|HANDEL_SERVICE_NAME||This is the value of the <service_name> field from your Handel file. It is the name of the currently deployed service.|
|HANDEL_PARAMETER_STORE_PREFIX||This is the prefix used for secrets stored in Parameter Store.|
|HANDEL_REGION_NAME||This is the value of the <region_name> field from your Handel file, or the current region if the region id not specified.|