• Documentation
  • Pricing
© 2026 Serverless, Inc. All rights reserved.

Framework

  • Overview
  • Documentation
  • Plugins360
  • Pricing

Learn

  • Blog
  • GuidesUpdated
  • Examples240
  • Courses

Resources

  • Support
  • Security
  • Trust Center
  • Status

Community

  • Slack
  • GitHub47k
  • Forum
  • Meetups

Company

  • About
  • Careers
  • Contact
  • Partners

Legal

  • Terms of Service
  • Privacy Policy
  • Trademark
  • DMCA
Serverless Framework Logo

Serverless Framework

Intro
SetupUpgrading To V4ConceptsTutorialAWS CredentialsLicense KeysVerifying Downloads
DeployingPackagingBuildingTestingDev ModeServicesFunctions
OverviewHTTP (API Gateway v2)REST (API Gateway v1)ActiveMQApplication Load BalancerAlexa SkillAlexa Smart HomeCloudWatch EventCloudWatch LogCloudFrontCognito User PoolEventBridge EventIoTIoT Fleet ProvisioningKafkaKinesis & DynamoDBMSKRabbitMQS3ScheduleSNSSQSWebsocket
Layers
OverviewTroubleshooting
Managed InstancesWeb Apps (Lambda Web Functions)Sandboxes (Lambda MicroVMs)MCP ServersAlertsVersion PruningDomainsIAM Function PermissionsParameters
OverviewSelf-reference serverless.ymlServerless CoreEnvironment VariablesCLI OptionsExternal YAML/JSON FilesJavascript propertiesGitDoppler
OverviewS3 ObjectsSSM Parameter Store & Secrets ManagerCloudFormation Stack Outputs
OverviewVaultTerraform State Output
ResourcesComposing ServicesDeployment BucketStateAgent SkillsPython support
OverviewRuntimeGatewayMemoryBrowserCode InterpreterDev Mode
API Gateway Proxy
OverviewGeneral ConfigurationAuthenticationAPI KeysData SourcesResolversPipeline FunctionsSubstitutionsCachingDelta SyncCustom DomainWAFCLI Commands
Deploying SAM/CFN TemplatesWorkflow Tips
OverviewCreating PluginsCLI OutputCustom CommandsCustom VariablesExtending the Configuration schemaExtending and overriding configuration
OverviewDashboardAxiom
Overviewagent docsagent inspectagent setupagent skills installagent skills list / readdeploydeploy functiondeploy listdevdiffinfoinvokeinvoke localloginlogin awslogin aws ssologsmetricspackageplugin installplugin uninstallprintprunereconcileremoverollbackrollback functionusage
OverviewConcepts
OverviewMetricsTracesTroubleshoot
OverviewNode.jsPython
OutputsProviders
OverviewBranch DeploymentsPreview DeploymentsCustom ScriptsTestingPrivate PackagesNotificationsMono ReposDeploy in your own CI/CDBest PracticesTroubleshootingFAQ
OverviewSetupToolsAWS Integration
Serverless.yml Reference
Examples and TutorialsConfiguration Validation
  1. Usage
  2. Events
  3. Active MQ

Amazon MQ for ActiveMQ Events

The activemq event triggers a Lambda function with messages from a queue on an Amazon MQ for Apache ActiveMQ broker. The Framework creates a Lambda event source mapping: Lambda reads the queue, invokes the function with batches of messages, and acknowledges them after the function succeeds. The activemq event connects to an existing broker and queue in the same AWS account; for an Amazon MQ for RabbitMQ broker, use the rabbitmq event. Lambda consumes queues only; to receive messages sent to a topic, use an ActiveMQ virtual destination, which Lambda reads as a queue.

The activemq event requires the broker's arn, the queue and basicAuthArn, the ARN of an AWS Secrets Manager secret that holds the broker user's sign-in credentials. This serverless.yml consumes the orders queue:

# serverless.yml
service: my-service

provider:
  name: aws
  runtime: nodejs24.x

functions:
  compute:
    handler: handler.compute
    events:
      - activemq:
          arn: arn:aws:mq:us-east-1:123456789012:broker:ExampleMQBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9
          queue: orders
          basicAuthArn: arn:aws:secretsmanager:us-east-1:123456789012:secret:MyBrokerSecret-AbCdEf

The handler receives the messages in event.messages, each with its body in data as a base64-encoded string:

// handler.mjs
export const compute = async (event) => {
  for (const message of event.messages) {
    const body = Buffer.from(message.data, 'base64').toString('utf8')
    console.log(message.messageID, body)
  }
}

Lambda must reach the broker: either it has a public endpoint, or Lambda needs network access to the broker's VPC; see Configure network security.

activemq event options

The activemq event accepts these keys:

KeyTypeDefaultDescription
arnbroker ARN, Ref or Fn::ImportValueRequiredThe Amazon MQ broker
queuestringRequiredThe queue to consume; one queue per event
basicAuthArnSecrets Manager secret ARN, Ref or Fn::ImportValueRequiredThe secret with the broker credentials
batchSizenumber, 1–10000100The largest number of messages in one invocation
maximumBatchingWindownumber, 0–300 seconds500 msHow long Lambda gathers messages before it invokes the function
filterPatternslist of 1–10 patternsNo filterPatterns a message must match to reach the function
enabledbooleantrueWhether Lambda reads the queue

The broker ARN has the form arn:aws:mq:<region>:<account>:broker:<name>:<broker id>.

Batch size and batching window

The activemq event's batchSize sets the largest number of messages in one invocation, and maximumBatchingWindow sets how many seconds Lambda gathers messages before it invokes the function:

functions:
  compute:
    handler: handler.compute
    events:
      - activemq:
          arn: arn:aws:mq:us-east-1:123456789012:broker:ExampleMQBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9
          queue: orders
          basicAuthArn: arn:aws:secretsmanager:us-east-1:123456789012:secret:MyBrokerSecret-AbCdEf
          batchSize: 5000
          maximumBatchingWindow: 30
  • batchSize: 1 to 10000; AWS uses 100 when it isn't set.
  • maximumBatchingWindow: 1 to 300 seconds. When it isn't set, AWS uses a 500 ms window. The Framework doesn't pass 0, so 0 also leaves the 500 ms default in place on a new event source mapping. AWS can't return an existing mapping to 500 ms once its window has been 1 second or more: removing maximumBatchingWindow or setting 0 doesn't restore it. To restore the 500 ms default, remove the event and deploy, then add the event back without maximumBatchingWindow and deploy again, which creates a new mapping.

Lambda invokes the function when the batch is full, when the window ends, or when the batch reaches the 6 MB payload limit, whichever comes first. See Batching behavior.

Filter patterns

The activemq event's filterPatterns passes only the messages that match at least one pattern. Amazon MQ event source mappings filter on the data key, which holds the message body; a pattern on body fields matches only bodies that are valid JSON. This example passes only messages whose field a is 1 or 2:

functions:
  compute:
    handler: handler.compute
    events:
      - activemq:
          arn: arn:aws:mq:us-east-1:123456789012:broker:ExampleMQBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9
          queue: orders
          basicAuthArn: arn:aws:secretsmanager:us-east-1:123456789012:secret:MyBrokerSecret-AbCdEf
          filterPatterns:
            - data:
                a: [1, 2]
  • Lambda acknowledges messages that match no pattern without invoking the function, so they leave the queue.
  • AWS allows 5 patterns per event source mapping by default, and up to 10 with a quota increase; the Framework accepts up to 10.

For the pattern syntax, see Event filtering with Amazon MQ event sources.

Function timeout

A function with an activemq event can have a timeout of at most 900 seconds (15 minutes), on standard and Managed Instances functions alike: Lambda rejects an Amazon MQ event source mapping for a function with a longer timeout. AWS recommends 840 seconds or less, so that the event source mapping can handle function errors and retries (Using Lambda with Amazon MQ). A longer timeout, set on the function or inherited from provider.timeout, stops packaging with this error:

Function "compute" has a timeout of 1800 seconds, and Lambda allows at most 900 seconds for functions with "activemq" events. Set its timeout to 900 or less.

To fix it, set the function's own timeout to 900 or less.

Concurrency

Lambda runs at most five execution environments at a time for each activemq event source mapping. Reserved or provisioned concurrency on the function doesn't raise this limit; to raise it, contact AWS Support with the event source mapping's UUID and Region. See Using Lambda with Amazon MQ.

Disable the event source mapping

To stop Lambda from reading the queue without removing the mapping, set the activemq event's enabled: false:

functions:
  compute:
    handler: handler.compute
    events:
      - activemq:
          arn: arn:aws:mq:us-east-1:123456789012:broker:ExampleMQBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9
          queue: orders
          basicAuthArn: arn:aws:secretsmanager:us-east-1:123456789012:secret:MyBrokerSecret-AbCdEf
          enabled: false

IAM permissions for ActiveMQ events

For activemq events, the Framework adds these permissions to the execution role it generates (the service's shared role, or each function's role with provider.iam.role.mode: perFunction). When the function uses a role of your own, set in provider.iam.role as an ARN, in provider.role or in the function's role, add them to that role:

  • secretsmanager:GetSecretValue on each basicAuthArn secret.
  • mq:DescribeBroker on each broker.
  • ec2:CreateNetworkInterface, ec2:DescribeNetworkInterfaces, ec2:DescribeVpcs, ec2:DeleteNetworkInterface, ec2:DescribeSubnets and ec2:DescribeSecurityGroups.

When the secret is encrypted with a customer managed KMS key, add kms:Decrypt on that key yourself:

provider:
  name: aws
  runtime: nodejs24.x
  iam:
    role:
      statements:
        - Effect: Allow
          Action: kms:Decrypt
          Resource: arn:aws:kms:us-east-1:123456789012:key/1234abcd-12ab-34cd-56ef-1234567890ab

See Using Lambda with Amazon MQ and IAM permissions for functions.

Related

  • Amazon MQ for RabbitMQ events
  • ActiveMQ settings in the serverless.yml reference
  • How Lambda processes Amazon MQ messages
Edit this page
Prev REST (API Gateway v1)NextApplication Load Balancer

Contents

  • Amazon MQ for ActiveMQ Events
  • activemq event options
  • Batch size and batching window
  • Filter patterns
  • Function timeout
  • Concurrency
  • Disable the event source mapping
  • IAM permissions for ActiveMQ events
  • Related

Related

GuidesPluginsExamplesSlack CommunitySupport