aws / aws/serverless-application-model
Step Function Execution Role is created although an existing Role is specified in the template
- Dominant language
- Python
- Stars
- 9.6k
- Forks
- 2.5k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 7
Description
**Description:**
The app structure is an API with 5 routes, 4 of the endpoints hit individual lambdas and the fifth initiates a step function state machine process. All of this is built out with the SAM CLI tooling.
In my organization there is a strict IAM policy. I have managed to procure all of the Policies needed for the permissions associated with deploying a SAM CLI application under a role they gave me. From what I understand, the logic behind the IAM role creation permissions and the sam deploy function is essentially screening the application template for any roles needed, if roles are specified, it uses those roles, otherwise it auto generates ones specific to the needs of the application being deployed.
We are not allowed to have iam:createRole permissions.
I have tried to circumvent this by getting the roles with all of the theoretical permissions needed and then specifying those roles into the formation template.
In the template, all of the lambdas have roles specified and during deployment the build tasks of creating roles for each lambda were removed as a result. This is expected functionality.
I have specified a role for the state machine in the template as well, the role has the full access policy for step functions along with all other needed permissions.
The event type to activate the state machine is an api event. During deployment, there is still a trigger to create a new iam role related to the state machines specific api event. Providing the predefined role to every other resource seemed to do the trick. Why does it keep doing this only for the state machines api event?
Just to emphasize, I fixed this issue for the lambdas and the autogenerated api by specifying roles for each resource, but for some reason it did not work with the state machine's api event.
I have tried this with capabilities defined as both CAPABILITY_IAM and CAPABILITY_NAMED_IAM in the deploy command.
I used issue #1009 to fix the role issues with the Lambdas but the same logic did not work for the state machine resource.
here is the template yaml for reference, the naming or references might be weird on here because I tried to scrub it for anything related to the actual project and make it general.
I am new so hopefully this is just a template syntax issue on my end.
Thank you in advance
[Similar issue also posted but unasnwered on StackOverflow](https://stackoverflow.com/questions/64034602/why-is-my-sam-stepfunctions-state-machine-still-creating-the-implicit-api-event)
```
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: >
sam template
Resources:
stateMachine:
Type: AWS::Serverless::stateMachine
Properties:
DefinitionUri: statemachine/state_machine_logic_here.asl.json
DefinitionSubstitutions:
firstFunctionArn: !GetAtt firstFunction.Arn
secondFunctionArn: !GetAtt secondFunction.Arn
thridFunctionArn: !GetAtt thirdFunction.Arn
fourthFunctionArn: !GetAtt fourthFunction.Arn
Events:
ApiEvent:
Type: Api
Properties:
Method: get
Path: /activate_state_machine
Role: arn:aws:iam::13333333333337:role/service-role/rolename
firstFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/first/
Handler: app.lambda_handler
Runtime: python3.8
Events:
ApiEvent:
Type: Api
Properties:
Method: get
Path: /first
Role: arn:aws:iam::13333333333337:role/rolename
secondFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/second/
Handler: app.lambda_handler
Runtime: python3.8
Events:
ApiEvent:
Type: Api
Properties:
Method: post
Path: /second
Role: arn:aws:iam::13333333333337:role/rolename
thirdFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/third/
Handler: app.lambda_handler
Runtime: python3.8
Events:
ApiEvent:
Type: Api
Properties:
Method: post
Path: /third
Role: arn:aws:iam::13333333333337:role/rolename
fourthFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/fourth/
Handler: app.lambda_handler
Runtime: python3.8
Events:
ApiEvent:
Type: Api
Properties:
Method: post
Path: /fourth
Role: arn:aws:iam::13333333333337:role/rolename
Outputs:
stateMachineArn:
Description: "state machine ARN"
Value: !Ref stateMachine
```
Observed result:
CloudFormation attempts to create a state machine api event role, and fails because current aws role hasn't been granted permissions to create IAM Roles.
Expected result:
The deployment should succeed because CloudFormation should NOT create a new role, as a Role has already been provided in the SAM template.
Contributor guide
Assessment
This issue has not been assessed yet.