Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dhavaln
Last active December 29, 2020 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhavaln/9acebc460d1fd9b558f2ca47795ecb71 to your computer and use it in GitHub Desktop.
Save dhavaln/9acebc460d1fd9b558f2ca47795ecb71 to your computer and use it in GitHub Desktop.
S3 Access Auth Role
- PolicyName: !Join ["-", [ "CognitoIDP", { Ref: AWS::StackName }, "S3-Access", "Policy"]]
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: "AllowListingPublicFiles"
Effect: Allow
Action: "s3:ListBucket"
Condition:
StringLike:
"s3:prefix":
- "public-files/*"
Resource: !Join ["", [ "arn:aws:s3:::", { Ref: s3FileBucket }]]
- Sid: "AllowListingUserFiles"
Effect: Allow
Action: "s3:ListBucket"
Condition:
StringLike:
"s3:prefix":
- !Join ["", [ 'users/', '${cognito-identity.amazonaws.com:sub', '}/*']]
Resource:
- !Join ["", [ "arn:aws:s3:::", { Ref: s3FileBucket }]]
- Sid: "AllowReadAccessPublicFolder"
Effect: Allow
Action:
- "s3:GetObject"
Resource:
- !Join ["", [ "arn:aws:s3:::", { Ref: s3FileBucket }, '/public-files']]
- !Join ["", [ "arn:aws:s3:::", { Ref: s3FileBucket }, '/public-files/*']]
- Sid: "ReadWriteDeleteOwnFiles"
Effect: Allow
Action:
- "s3:GetObject"
- "s3:PutObject"
- "s3:DeleteObject"
Resource:
- !Join ["", [ "arn:aws:s3:::", { Ref: s3FileBucket }, '/users/', '${cognito-identity.amazonaws.com:sub', '}']]
- !Join ["", [ "arn:aws:s3:::", { Ref: s3FileBucket }, '/users/', '${cognito-identity.amazonaws.com:sub', '}/*']]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment