OpsCanary
awsiamPractitioner

Custom Execution Roles for AWS CloudFormation StackSets: A Game Changer

5 min read AWS DevOps BlogNov 20, 2026Reviewed for accuracy
Share
Practitioner — Hands-on experience recommended

The introduction of custom execution roles for AWS CloudFormation StackSets addresses a critical need for organizations aiming for least-privilege access. Instead of relying on a default AdministratorAccess role, you can define specific IAM roles that StackSets will use in each member account, allowing for more granular control over permissions.

When you create or update a stack set with a custom execution role template, StackSets validates and stores it. It then deploys this template as a small bootstrapping stack in each target member account, creating the IAM role you specified. You'll pass the role name through the ExecutionRoleName parameter for all subsequent operations. The execution role template itself must be defined in either JSON or YAML format, and it requires the CAPABILITY_NAMED_IAM capability to function correctly.

In production, be aware that switching to a custom execution role does not remove the default AdministratorAccess role from member accounts. For true least-privilege access, you should delete this default role after confirming that your custom role works as intended. Additionally, if you're using an S3 URL for your execution role template, ensure your credentials have read access to that resource.

Key takeaways

  • →Define custom execution role templates to enhance security in StackSets.
  • →Use the ExecutionRoleName parameter for all subsequent operations after creating a stack set.
  • →Ensure your execution role template has the CAPABILITY_NAMED_IAM capability.
  • →Delete the default AdministratorAccess role for least-privilege access after confirming custom roles work.
  • →Verify read access to S3 URLs when using them for execution role templates.

Why it matters

This feature allows for tighter security controls and tailored permissions, reducing the risk of over-privileged access in your AWS environment.

Code examples

Bash
1aws cloudformation create-stack-set \
2--stack-set-name my-sam-stack-set \
3--template-body file://my-sam-template.yaml \
4--permission-model SERVICE_MANAGED \
5--execution-role-template-body file://execution-role-template.yaml \
6--execution-role-name stacksets-exec-custom-my-role \
7--capabilities CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND
YAML
1AWSTemplateFormatVersion: "2010-09-09"
2Description: Custom execution role for CloudFormation StackSets
3Resources:
4  StackSetExecutionRole:
5    Type: AWS::IAM::Role
6    Properties:
7      RoleName: stacksets-exec-custom-my-role
8      AssumeRolePolicyDocument:
9        Version: "2012-10-17"
10        Statement:
11          - Effect: Allow
12            Principal:
13              AWS: arn:aws:iam::123456789012:role/aws-service-role/stacksets.cloudformation.amazonaws.com/AWSServiceRoleForCloudFormationStackSetsOrgAdmin
14            Action: sts:AssumeRole
15      Policies:
16        - PolicyName: StackSetExecutionPolicy
17          PolicyDocument:
18            Version: "2012-10-17"
19            Statement:
20              - Effect: Allow
21                Action:
22                  - s3:CreateBucket
23                  - s3:DeleteBucket
24                  - s3:PutBucketPolicy
25                  - s3:GetBucketPolicy
26                Resource: "arn:aws:s3:::amzn-s3-demo-*"
27              - Effect: Allow
28                Action: cloudformation:*
29                Resource: "*"
30Outputs:
31  StackSetExecutionRoleName:
32    Value: !Ref StackSetExecutionRole
33    Description: Name of the execution role used by StackSets
Bash
1aws cloudformation create-stack-set \
2--stack-set-name my-stack-set \
3--template-body file://my-stackset-template.yaml \
4--permission-model SERVICE_MANAGED \
5--execution-role-template-url https://s3.amazonaws.com/amzn-s3-demo-bucket/execution-role-template.yaml \
6--execution-role-name stacksets-exec-custom-my-role \
7--capabilities CAPABILITY_NAMED_IAM

When NOT to use this

The official docs don't call out specific anti-patterns here. Use your judgment based on your scale and requirements.

Want the complete reference?

Read official docs

Test what you just learned

Quiz questions written from this article

Take the quiz →
DigitalOceanSponsor

Simple, affordable cloud — VMs, Kubernetes, and managed databases in minutes. Trusted by 600,000+ developers. Spin up a Droplet in 60 seconds.

Try DigitalOcean →

Get the daily digest

One email. 5 articles. Every morning.

No spam. Unsubscribe anytime.