Skip to content

Latest commit

 

History

History
71 lines (51 loc) · 5.95 KB

lambda.md

File metadata and controls

71 lines (51 loc) · 5.95 KB

Running Welt on AWS Lambda

On AWS Lambda, Welt serves Slack over HTTP: lambda_function.py is the handler, running on the Lambda Python runtime, and Slack sends events and button presses to its Function URL. template.yaml is an AWS SAM template that creates the function, its IAM role, and the Function URL.

The setup below assumes you already have an agent on AgentCore Runtime, a managed harness, or an agent served over HTTP elsewhere, such as on Lambda Web Functions, for the function to invoke.

Setup

  1. Create a Slack app from manifest.yml — the pre-filled creation screen is the quickest way there. Choose your workspace, then Next, Create and Install, and Allow. Two values come out of it; serving over HTTP needs no app-level token:

    • On the screen that says the app is ready, open Your app credentials and copy the Bot token (xoxb-...). If you closed that screen, it is under Install App.
    • Choose Go to App Settings, and on the Basic Information page that opens, copy the Signing Secret.
  2. Deploy using the release ZIP or build the function from source.

    Release ZIP

    Choose a tag with Lambda assets in GitHub Releases. Download the ZIP and its configured SAM template into the same directory, then deploy:

    gh release download vX.Y.Z --repo iwamot/welt --pattern 'welt-lambda-*.zip' --pattern template.yaml
    sam deploy --template-file template.yaml --guided

    To update an existing function through the Lambda console, match its runtime, architecture, and handler to WeltFunction.Properties in the same template, then upload the ZIP.

    Build from source

    git clone https://github.com/iwamot/welt.git
    cd welt
    sam build
    sam deploy --guided

    During sam deploy --guided:

    • Set SlackBotToken and SlackSigningSecret from step 1, or store them in a Secrets Manager secret as the JSON keys SLACK_BOT_TOKEN and SLACK_SIGNING_SECRET and set SlackSecretArn to its ARN instead. With the secret, the tokens stay out of the function's environment variables, as Lambda recommends, and the template lets the function read only that secret. Welt reuses the secret for five minutes, the default cache period of the AWS Parameters and Secrets Lambda Extension, so an edited secret takes effect within five minutes. For the agent, set AgentArn for direct invocation, or AgentGatewayUrl and GatewayArn for Gateway routing. Supplying all three uses the Runtime SDK through the Gateway.
    • Set the agent to invoke: AgentArn for a Runtime agent or harness, AgentGatewayUrl and GatewayArn for a Gateway, or AgentUrl for an agent served by URL, with AgentSigv4Service, AgentSigv4Region and WebFunctionArn for a Lambda Web Function.
    • Optionally, set QueueArn to take requests from outside Slack from an SQS FIFO queue.
    • Answer y to Allow SAM CLI IAM role creation — the template creates the function's role.
    • Answer y to WeltFunction Function Url has no authentication. Is this okay? — it defaults to no, and Slack requests are verified with the signing secret instead.
    • Note the FunctionUrl stack output; the next step needs it.
  3. In the Slack app manifest, edit the settings: section: add a request_url with the FunctionUrl output under event_subscriptions and again under interactivity, so events and button presses arrive at the function, then set socket_mode_enabled to false:

    settings:
      event_subscriptions:
        request_url: https://<url-id>.lambda-url.<region>.on.aws/  # the FunctionUrl output
        bot_events:
          - message.channels
          - message.groups
          - message.im
          - message.mpim
      interactivity:
        is_enabled: true
        request_url: https://<url-id>.lambda-url.<region>.on.aws/  # the same FunctionUrl
      socket_mode_enabled: false

    After saving, Slack reports that the request URL isn't verified and offers to verify it; do so. The function answers Slack's challenge, which is why it is deployed before this step.

Notes

  • Agent replies are bounded by Lambda's 15-minute cap, shorter than AgentCore Runtime's 60 minutes, and a reply that hits it is not retried. Deployment compares the limits on both sides.
  • The optional variables in Configuration go under Environment.Variables in template.yaml.
  • To redeploy from source after a change, run sam build && sam deploy. When using a release ZIP, repeat the release ZIP steps with the desired tag.
  • sam delete removes everything the setup created.