keatontaylor / alexa-actions

A README and associated code to get actionable notifications setup for Alexa devices.
GNU General Public License v3.0
391 stars 186 forks source link

Add tailscale integration #251

Closed MelleD closed 1 day ago

MelleD commented 4 months ago

This PR makes it possible to start the lambda function as a container and connect to the home assistant via Tailscale VPN. This means that it is not necessary to put your HA on the Internet.

Open points are the adaptation of the wiki and documentation. In addition, you have to clone the repo so that the Docker container can be pushed into its own ECR container in AWS.

In addition, you have to think about how to design the githubaction

If you use PY lamdba directly you now have to adapt the config.py and/or if possible also use ENV variables, then the user no longer has to adapt py at all.

I'm looking forward to feedback.

DEADSEC-SECURITY commented 4 months ago

Please add your proposed changes to the wiki to explain how to use and the features it has

MelleD commented 4 months ago

Yes, of course I will do it if the changes are ok with the config.py too. In the end you only have to set the Ha-Url, Ha-Token and auth Tailscale Key. But I will describe the workflow with forking and adding images, but it takes a bit of effort ;)

DEADSEC-SECURITY commented 4 months ago

Thats ok with me.

DEADSEC-SECURITY commented 4 months ago

Please dont edit the wiki directly. Write any mods or new text in here so I can double check before making the changes permanent

MelleD commented 4 months ago

Here are some steps you need to take:

The premise is that Tailscale Integration is installed in HA and the HA instance is available as a node.

  1. The Git repo must be forked so that the Docker image for the AWS Lambda can be pushed to a private repository in the Amazon Elastic Container Registry.
  2. Create a private repository on AWS Amazon Elastic Container Registry. The name must be ha-custom-lambda-tailscale for the repo ecr-private

[AWS Introduction ECR] (https://aws.amazon.com/de/ecr/getting-started/)

  1. Create a keypair on AWS IM to allow github action to push the Docker image Create AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY zugriff_schlüssel

[AWS Introduction credentials] (https://docs.aws.amazon.com/de_de/keyspaces/latest/devguide/access.credentials.html#SigV4_credentials)

Remember both carefully because the secret is only displayed once and is required in the next step.

  1. Go to your formed repo under settings. Go to secrets and variables. Create two new secrets with AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY from the previous step

    github secret
  2. Then build and push the Docker image under Github Actions.To do this, run .github/workflows/docker-build-push.yml

    githubaction

Congratulations! This is the first step and the result should look like this.

  1. Create a new function. Select Container Image at the top add-lambda

[AWS Lambda] (https://docs.aws.amazon.com/de_de/lambda/latest/dg/getting-started.html)

  1. Name the function alexa-actionable-notifications-function and select the Docker image from the ECR and click create function lambda1
create-lambda lambda Kopie

3.Click "Add Trigger" and copy your skill id from the previous step from the https://developer.amazon.com/alexa/console/ask skill

lambda-alexa skill trigger
  1. Now we have to log in to our Tailscale account and create an ephemeral key. Go to settings --> key

    key key1

    Please remember the key. You currently have to do this step every 3 months because the key can no longer be created

  2. An HA long-living token (10 years) must then be created. See instructions above Please remember the key.

  3. Now the following ENV variables must be inserted into the function.

    ha-env

DEBUG true/false HA_TOKEN HA_URL Important the TAILSCALE ip from HA e.g http://{tailscale-ha-ip}:8123. Should be start with 100.xxx.xxx.xxx TAILSCALE_AUTHKEY the ephemeral key. Should be start with tskey-auth-xxxxx

  1. Save function to deploy the function new

Now the Alexa skill can be tested and integrated into HA. These are the same steps.

The only thing that changes in the Alexa Skill chapter in the editor is that you don't have to create a PY for the template. Actually always click Customize

Troubleshooting: I rarely get timeouts from tailscale. Ticket is open. That's why I increased the timeout to 10 seconds.

Bildschirmfoto 2024-04-28 um 12 18 18

Danger: The ECR and the AWS Lambda can cost money. For this reason the image was kept small. But you have to have a lot of traffic and updates. With testing and everything, my most expensive month was 4 cents ;)

MelleD commented 2 months ago

Ping :)

github-actions[bot] commented 1 week ago

Stale pull request message