In order to start using AWS Lambda Functions with Ably, there's a few things you need to setup both with Lambda as well as Ably.


1. Create a IAM role for your Reactor Function

Navigate to the IAM page, and select 'Create role'. From here, create a role which gives access to whatever you wish your Reactor Function to access.



2. Ensure you've created an IAM user for use by the Ably Reactor

In order for Reactor Functions to interact with your Lambda function, you'll need to create a role which it can use. Navigate to the IAM section of the AWS site, and go through the following:


  1. Select “Users” from the left menu
  2. Click the blue “Add user” button
  3. For the “Add User” form that is displayed:
  4. Add a username
  5. Check the “Programmatic access” checkbox
  6. Click the blue “Next: permissions” button in the bottom right corner of the page
  7. For the “Set permissions for username” page:
  8. Add the role you created previously
  9. Click the blue “Next: Review” in the bottom right corner of the page
  10. Click the blue “Create user” button in the bottom right corner of the page
  11. Your new user will be displayed in a table and you’ll see two columns; “Access key ID” and “Secret access key”:
  12. Copy and paste the access key ID into a text file for later use
  13. Click the “Show” link in the last column, which will reveal the secret key
  14. Copy and paste the secret key into your text file


3. Add the IAM role to your Lambda function

During the creation of your Lambda function, or afterwards from the 'Execution role' section on the Lambda configuration page, add your IAM role.


4. Go to the Ably site, and visit your dashboard


5. Click on the Reactor tab and click "New Reactor Rule"

6. Click through "Reactor Event", then "AWS Lambda" to get to the configuration page


7. Configure your Reactor Function

Ensure you include the correct details of your Lambda Function. For the "AWS Credentials" box, fill it in with your Access Key ID and Secret Access Key from step 2.11 above, separated by a colon. So, in the form "[AccessKey]:[SecretKey]".


For more details on the impact of the other settings, such as envelopes, look here.


8. Publish an event through Ably!

Your Reactor Function should be ready to trigger when messages are sent on the channels it's listening to. Give it a try, and hopefully your Lambda Function will receive a request! If you're facing issues when trying this, take a look at this article on how to debug a Reactor Function.


9. Further help


If you want a detailed guide through making your first application with AWS Lambda and Ably Reactor Functions, check out our tutorials.