Skip to content

feat(event_sources): add support for Amazon Connect Outbound Campaigns - #8702

Open
ASHMEET555 wants to merge 2 commits into
aws-powertools:developfrom
ASHMEET555:feat/connect-outbound-campaigns
Open

ASHMEET555 wants to merge 2 commits into
aws-powertools:developfrom
ASHMEET555:feat/connect-outbound-campaigns

Conversation

@ASHMEET555

Copy link
Copy Markdown
Contributor

Issue number: closes #7976

Summary

Adds support for Amazon Connect Outbound Campaigns custom action block triggers, achieving feature parity with TypeScript implementation (aws-powertools/powertools-lambda-typescript#5502).

Changes

Event Source Data Classes

  • Added ConnectOutboundCampaignsEvent in aws_lambda_powertools/utilities/data_classes/connect_campaign_event.py with typed sub-wrappers:
    • ConnectOutboundCampaignInvocationMetadata & ConnectOutboundCampaignContext (CampaignId, RunId, ActionId, CampaignName).
    • ConnectOutboundCampaignItems & ConnectOutboundCampaignCustomerProfile (ProfileId, CustomerData, IdempotencyToken).
  • Added cached_property json_customer_data to automatically deserialize the embedded campaign JSON string.
  • Added convenience accessor event.customer_profiles to iterate directly over profiles.
  • Re-exported all new classes in aws_lambda_powertools/utilities/data_classes/__init__.py.

Parser (Pydantic v2)

  • Added built-in event model ConnectOutboundCampaignsEventModel in aws_lambda_powertools/utilities/parser/models/connect_campaign.py.
  • Added models ConnectInvocationMetadataModel, ConnectCampaignContextModel, ConnectItemsModel, and ConnectCustomerProfileModel.
  • CustomerData is typed Any by default, allowing developers to extend ConnectCustomerProfileModel with custom Pydantic schemas for campaign payloads.
  • Registered models for lazy-loading in aws_lambda_powertools/utilities/parser/models/__init__.py.

Documentation & Examples

  • Added Amazon Connect Outbound Campaigns entry and code sample in docs/utilities/data_classes.md.
  • Added standalone runnable example in examples/event_sources/src/connect_outbound_campaigns.py.
  • Added ConnectOutboundCampaignsEventModel to the built-in models reference table in docs/utilities/parser.md.

Tests & Fixtures

  • Added canonical event fixture in tests/events/connectOutboundCampaignsEvent.json (matches AWS documentation and TS fixture).
  • Added comprehensive unit tests for data classes in tests/unit/data_classes/required_dependencies/test_connect_campaign_event.py.
  • Added unit tests for parser models (valid parsing, missing fields validation, and custom schema extension) in tests/unit/parser/_pydantic/test_connect_campaign.py.

User experience

1. With Event Source Data Classes:

from aws_lambda_powertools.utilities.data_classes import (
    ConnectOutboundCampaignsEvent,
    event_source,
)
from aws_lambda_powertools.utilities.typing import LambdaContext

@event_source(data_class=ConnectOutboundCampaignsEvent)
def handler(event: ConnectOutboundCampaignsEvent, context: LambdaContext):
    campaign = event.invocation_metadata.campaign_context
    print(f"Processing {campaign.campaign_name} (ID: {campaign.campaign_id})")

    for profile in event.customer_profiles:
        # Access raw or auto-parsed customer data
        print(profile.profile_id, profile.json_customer_data)

2. With Parser:

from aws_lambda_powertools.utilities.parser import parse
from aws_lambda_powertools.utilities.parser.models import ConnectOutboundCampaignsEventModel

def handler(event: dict, context):
    parsed: ConnectOutboundCampaignsEventModel = parse(event=event, model=ConnectOutboundCampaignsEventModel)
    for profile in parsed.items.customer_profiles:
        print(profile.profile_id, profile.idempotency_token)

Verification

  • uv run pytest tests/unit/data_classes/required_dependencies/test_connect_campaign_event.py tests/unit/parser/_pydantic/test_connect_campaign.py --cov=aws_lambda_powertools.utilities.data_classes.connect_campaign_event --cov=aws_lambda_powertools.utilities.parser.models.connect_campaign — 4 passed, 100% test coverage.
  • uv run ruff check aws_lambda_powertools/ docs/ examples/ tests/ — Passed.
  • uv run ruff format --check — Passed.
  • uv run mypy aws_lambda_powertools/utilities/data_classes/ aws_lambda_powertools/utilities/parser/ — Success: no issues found in 98 source files.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@ASHMEET555
ASHMEET555 requested a review from a team as a code owner October 29, 2026 14:19
@ASHMEET555
ASHMEET555 requested a review from hjgraca October 29, 2026 14:19
@boring-cyborg boring-cyborg Bot added documentation Improvements or additions to documentation tests labels Oct 29, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 29, 2026
@ASHMEET555

Copy link
Copy Markdown
Contributor Author

Hi @leandrodamascena , PR is ready for review!

Includes Event Source Data Classes, Pydantic v2 Parser models, documentation, and 100% test coverage matching the TypeScript reference implementation.

@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.02%. Comparing base (486e484) to head (79e06ab).
⚠️ Report is 4 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8702      +/-   ##
===========================================
+ Coverage    96.99%   97.02%   +0.02%     
===========================================
  Files          321      323       +2     
  Lines        16332    16483     +151     
  Branches      1473     1483      +10     
===========================================
+ Hits         15841    15992     +151     
  Misses         350      350              
  Partials       141      141              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leandrodamascena leandrodamascena added the feature New feature or functionality label Oct 31, 2026
@leandrodamascena leandrodamascena added this to the 3.40.0 milestone Oct 31, 2026
@leandrodamascena leandrodamascena added the event_sources Event Source Data Class utility label Oct 31, 2026
… sends

Extending the model with a plain typed field fails on a real event because
CustomerData is a string; document and test the Json[...] pattern instead.
@sonarqubecloud

Copy link
Copy Markdown

@leandrodamascena leandrodamascena left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ASHMEET555, this matches the AWS docs and the TypeScript schema field by field. I pushed one commit on top: CustomerData is a JSON string on the wire, so a subclass with a plain typed field fails on a real event. The model now types it as str like TypeScript does, and the test shows the Json[YourModel] pattern on the real payload instead of a dict that the service never sends. One caveat for the record: a user in #7976 reported real payloads without InvocationMetadata back in July. The docs and TypeScript say otherwise and I could not run a real campaign to settle it, so we follow the docs; if someone hits that shape we will hear about it quickly.

I'm approving now. This goes out in 3.40.0, so it will sit here for a while before I merge it. No rebase needed in the meantime, and you'll be credited in the release notes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation event_sources Event Source Data Class utility feature New feature or functionality size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Add support for Connect Outbound Campaigns

2 participants