Last active
June 20, 2018 12:34
-
-
Save jincod/0720d10f8519d08dbd24bf67d2b49ef9 to your computer and use it in GitHub Desktop.
Based on https://gist.github.com/NicolasRitouet/7b8367b79734e01deb36ef707dae91a4 and https://github.com/serverless/serverless/issues/1439
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
--- | |
AWSTemplateFormatVersion: '2010-09-09' | |
Description: 'Cloudformation stack to manage permission to deploy a serverless service' | |
Parameters: | |
ServiceName: | |
Description: Name of the Service you want to deploy | |
Type: String | |
Resources: | |
## Users | |
ServerlessDeployUser: | |
Type: AWS::IAM::User | |
Properties: | |
ManagedPolicyArns: # Max 10 policies | |
- !Ref ServelessDeployCFPolicy | |
- !Ref ServelessDeployS3Policy | |
- !Ref ServelessDeployLogsPolicy | |
- !Ref ServelessDeployIAMPolicy | |
- !Ref ServelessDeployLambdaPolicy | |
## Managed policies | |
ServelessDeployCFPolicy: | |
Type: AWS::IAM::ManagedPolicy | |
Properties: | |
PolicyDocument: | |
Version: '2012-10-17' | |
Statement: | |
- Effect: Allow | |
Action: 'cloudformation:ValidateTemplate' | |
Resource: '*' | |
- Effect: Allow | |
Action: | |
- 'cloudformation:Describe*' | |
- 'cloudformation:List*' | |
- 'cloudformation:Get*' | |
- 'cloudformation:PreviewStackUpdate' | |
- 'cloudformation:CreateStack' | |
- 'cloudformation:UpdateStack' | |
- 'cloudformation:DeleteStack' | |
Resource: | |
- !Sub 'arn:aws:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/${ServiceName}-*' | |
ServelessDeployS3Policy: | |
Type: AWS::IAM::ManagedPolicy | |
Properties: | |
PolicyDocument: | |
Version: '2012-10-17' | |
Statement: | |
- Effect: Allow | |
Action: | |
- 's3:Get*' | |
- 's3:List*' | |
- 's3:CreateBucket' | |
- 's3:DeleteBucket' | |
Resource: | |
- !Sub 'arn:aws:s3:::${ServiceName}-*' | |
- Effect: Allow | |
Action: | |
- 's3:*' | |
Resource: | |
- !Sub 'arn:aws:s3:::${ServiceName}-*/*' | |
ServelessDeployLogsPolicy: | |
Type: AWS::IAM::ManagedPolicy | |
Properties: | |
PolicyDocument: | |
Version: '2012-10-17' | |
Statement: | |
- Effect: Allow | |
Action: | |
- 'logs:DescribeLogGroups' | |
Resource: !Sub 'arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group::log-stream:*' | |
- Effect: Allow | |
Action: | |
- 'logs:CreateLogGroup' | |
- 'logs:CreateLogStream' | |
- 'logs:DeleteLogGroup' | |
- 'logs:DeleteLogStream' | |
- 'logs:DescribeLogStreams' | |
- 'logs:FilterLogEvents' | |
Resource: !Sub 'arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*:log-stream:*' | |
ServelessDeployIAMPolicy: | |
Type: AWS::IAM::ManagedPolicy | |
Properties: | |
PolicyDocument: | |
Version: '2012-10-17' | |
Statement: | |
- Effect: Allow | |
Action: | |
- 'iam:GetRole' | |
- 'iam:PassRole' | |
- 'iam:CreateRole' | |
- 'iam:DeleteRole' | |
- 'iam:DetachRolePolicy' | |
- 'iam:PutRolePolicy' | |
- 'iam:AttachRolePolicy' | |
- 'iam:DeleteRolePolicy' | |
Resource: | |
- !Sub 'arn:aws:iam::${AWS::AccountId}:role/${ServiceName}-*-lambdaRole' | |
ServelessDeployLambdaPolicy: | |
Type: AWS::IAM::ManagedPolicy | |
Properties: | |
PolicyDocument: | |
Version: '2012-10-17' | |
Statement: | |
- Effect: Allow | |
Action: | |
- 'lambda:*' | |
Resource: | |
- !Sub 'arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${ServiceName}-*' | |
- Effect: Allow | |
Action: | |
- 'ec2:DescribeSecurityGroups' | |
- 'ec2:DescribeSubnets' | |
- 'ec2:DescribeVpcs' | |
Resource: '*' | |
- Effect: Allow | |
Action: | |
- 'events:Put*' | |
- 'events:Remove*' | |
- 'events:Delete*' | |
- 'events:Describe*' | |
Resource: | |
- !Sub 'arn:aws:events:${AWS::Region}:${AWS::AccountId}:rule/${ServiceName}-*' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment