fix(cloudformation): expand SAM Function Policies into a role + non-API events into triggers#1923
Merged
Merged
Conversation
…PI events into triggers A SAM AWS::Serverless::Function's `Policies` and `Events` were dropped by the transform, so a `sam deploy` produced a function with no execution role (every IAM-enforced call denied under #1880 enforcement) and no triggers (nothing ever invoked it). The transform now synthesizes the native resources the existing provisioner arms already handle: - `Policies` -> an implicit `AWS::IAM::Role` (`<Fn>Role`) whose trust policy allows lambda.amazonaws.com; managed-policy names/ARNs become ManagedPolicyArns, inline statement docs become inline policies. The function's Role is set to GetAtt the role. An explicit `Role` is kept as-is. - `Schedule`/`ScheduleV2` -> `Events::Rule` (ScheduleExpression) targeting the function + `Lambda::Permission`. - `SQS`/`DynamoDB`/`Kinesis`/`MSK`/`MQ` -> `Lambda::EventSourceMapping`. - `SNS` -> `SNS::Subscription` (protocol lambda) + `Lambda::Permission`. - `EventBridgeRule`/`CloudWatchEvent` -> `Events::Rule` (EventPattern) + permission. Api/HttpApi events (implicit-API route synthesis) follow in a separate change. SAM policy *templates* (DynamoDBCrudPolicy etc.) aren't expanded into statements yet — the role is still created so the function is no longer role-less. Adds unit tests for the expansion and an E2E test deploying a function with Policies + Schedule + SQS events and asserting the role, Events::Rule target, and EventSourceMapping are all created.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary (part of CRITICAL 1.1/1.2)
A SAM
AWS::Serverless::Function'sPoliciesandEventswere dropped by the transform →sam deployproduced a function with no execution role (every IAM-enforced call denied under #1880) and no triggers (nothing invoked it).The transform now synthesizes the native resources the existing provisioner arms handle:
Policies→ implicitAWS::IAM::Role(<Fn>Role, trust = lambda.amazonaws.com); managed names/ARNs →ManagedPolicyArns, inline statement docs → inline policies; functionRole=GetAtt. ExplicitRolekept.Schedule/ScheduleV2→Events::Rule(+Lambda::Permission).SQS/DynamoDB/Kinesis/MSK/MQ→Lambda::EventSourceMapping.SNS→SNS::Subscription(lambda) + permission.EventBridgeRule/CloudWatchEvent→Events::Rule(EventPattern) + permission.Api/HttpApi events (implicit-API route synthesis) follow in the next PR. SAM policy templates (DynamoDBCrudPolicy etc.) aren't expanded into statements yet — the role is still created so the function is no longer role-less.
Non-code surface
Internal CFN/SAM transform fidelity; SAM functions/events already documented as supported. No SDK/docs/metadata change applies (checked).
Test plan
expand_function_extras(Policies→role, explicit-role kept, Schedule→rule, SQS→ESM) + updated the Globals-additive-Policies test (merged list now lands in the role).sam_function_expands_policies_and_events: deploys a function with Policies + Schedule + SQS events; asserts the role (managed+inline), Events::Rule target, and EventSourceMapping are created.cargo test -p fakecloud-cloudformation --lib(242) + existing SAM e2e pass; clippy clean.Summary by cubic
Fixes the SAM transform dropping
AWS::Serverless::FunctionPoliciesand non-APIEvents. Functions now deploy with a proper execution role and working triggers.Policies→ synthesizeAWS::IAM::Role(<Fn>Role): managed names/ARNs →ManagedPolicyArns, inline statements → inline policies; set functionRoletoGetAttof the role; keep explicitRoleunchanged.Events→ native triggers:Schedule/ScheduleV2→AWS::Events::Rule+AWS::Lambda::PermissionSQS/DynamoDB/Kinesis/MSK/MQ→AWS::Lambda::EventSourceMappingSNS→AWS::SNS::Subscription(lambda) + permissionEventBridgeRule/CloudWatchEvent→AWS::Events::Rule+ permissionWritten for commit 44ab1c6. Summary will update on new commits.