Skip to main content

Hosting with AWS Lambda

You can develop a SmartThings SmartApp as an AWS Lambda function. This requires that you grant SmartThings permission to execute your Lambda function. You must also register your Lambda function with SmartThings as a SmartApp to be integrated into SmartThings. The steps below will guide you through the hosting process.

Deploy your Lambda function

Ensure that you deployed your Lambda function on AWS properly. Serverless CLI makes this task much smoother. Assuming you have AWS credentials configured correctly and a minimal serverless.yml, it can be as easy as typing serverless deploy. For examples on implementing serverless computing, see our Lambda examples.

To confirm that your Lambda function is deployed properly:

  1. Login to your AWS console
  2. Navigate to Services > Lambda. You should see your function listed here.

Provide permission to SmartThings

Next, you will need to grant SmartThings permission to execute this Lambda function. There are two ways you can grant permissions; only one method is required.

Option A: Use the SmartThings CLI

See smartthings apps:authorize for info on how to authorize using the SmartThings CLI.

Option B: Use the AWS CLI

To authorize using the AWS CLI, execute the following command in a terminal shell.

aws lambda add-permission --profile <my-profile-name> --function-name <my-function-name> --statement-id smartthings --principal <PRINCIPAL ID FROM SMARTTHINGS> --action lambda:InvokeFunction
  • where <my-profile-name> is your named profile as stored in your AWS config file. See here for more information.
  • <my-function-name> is the name of your Lambda function in AWS. This is the same as the value of the environment variable LAMBDA_FUNCTION_NAME. You can locate this environment variable on your Lambda function page of your AWS console.
  • <PRINCIPAL ID FROM SMARTTHINGS> is the account id to which you are granting the permission to execute your Lambda function. Use 906037444270 for SmartApp and 148790070172 for SmartThings Schema.
caution

To confirm that the permission is properly granted to the SmartThings account:

  1. Navigate to the Lambda function page on your AWS console,
  2. Click the Triggers tab and click the View function policy down arrow. This will display JSON description showing that SmartThings can now invoke your function.

Register your Lambda function with SmartThings

Before you register your SmartApp, make a note of the ARN for your Lambda function. You can find the ARN of your Lambda function from the Lambda function page on your AWS console. Read more about ARNs on Amazon's documentation.

After making a note of your ARN, head to SmartApp Registration to complete the registration process.