home-assistant.io/source/_components/notify.aws_lambda.markdown
2016-05-21 11:39:02 +02:00

3.5 KiB

layout title description date sidebar comments sharing footer logo ha_category ha_release
page AWS Lambda Instructions how to invoke AWS Lambda functions from Home Assistant. 2016-05-14 16:35 true false true true aws_lambda.png Notifications 0.20

The aws_lambda notification platform enables invoking AWS Lambda functions.

To use this notification platform in your installation, add the following to your configuration.yaml file:

Configuration

# Example configuration.yaml entry
notify:
  platform: aws_lambda
  name: NOTIFIER_NAME
  aws_access_key_id: AWS_ACCESS_KEY_ID
  aws_secret_access_key: AWS_SECRET_ACCESS_KEY
  profile_name: AWS_PROFILE
  region_name: 'us-east-1'
  context:
    ...

Configuration variables:

  • aws_access_key_id (Required if aws_secret_access_key is provided): Your AWS Access Key ID. For more information, please read the AWS General Reference regarding Security Credentials. If provided, you must also provide an aws_secret_access_key and must not provide a profile_name.
  • aws_secret_access_key (Required if aws_access_key_id is provided): Your AWS Secret Access Key. For more information, please read the AWS General Reference regarding Security Credentials. If provided, you must also provide an aws_access_key_id and must not provide a profile_name.
  • profile_name (Optional): A credentials profile name. For more information, please see the boto3 documentation section about credentials.
  • region_name (Required): The region identifier to connect to. The default is us-east-1.
  • name (Optional): Setting the optional parameter name allows multiple notifiers to be created. The default value is notify. The notifier will bind to the service notify.NOTIFIER_NAME.
  • context (Optional): An optional dictionary you can provide to pass custom context through to the Lambda function. The context dictionary (if any) is combined with the same data available at the /api/config HTTP API route.

{% linkable_title Usage %}

AWS Lambda is a notify platform and thus can be controlled by calling the notify service as described here. It will invoke a Lambda for all targets given in the notification payload. A target can be formatted as a function name, an entire ARN (Amazon Resource Name) or a partial ARN. For more information, please see the boto3 docs.

The Lambda event payload will contain everything passed in the service call payload. Here is an example payload that would be sent to Lambda:

{
  "title": "Test message!",
  "target": "arn:aws:lambda:us-east-1:123456789012:function:ProcessKinesisRecords",
  "data": {
    "test": "okay"
  },
  "message": "Hello world!"
}

The context will look like this:

{
  "hass": {
    "components": ["recorder", "logger", "http", "logbook", "api", "frontend"],
    "latitude": 44.1234,
    "location_name": "Home",
    "longitude": 5.5678,
    "temperature_unit": "°C",
    "time_zone": "Europe/Zurich",
    "version": "0.20.0.dev0"
  },
  "custom": {
    "two": "three",
    "test": "one"
  }
}