Skip to content

Instantly share code, notes, and snippets.

@alexcasalboni
Created January 4, 2018 20:51
Show Gist options
  • Save alexcasalboni/b8ef59af46513a66b490a657cdafc799 to your computer and use it in GitHub Desktop.
Save alexcasalboni/b8ef59af46513a66b490a657cdafc799 to your computer and use it in GitHub Desktop.
Serverless Resources sample for Amazon Cognito IdentityPool
Resources:
WorkshopKinesisStream:
Type: "AWS::Kinesis::Stream"
Properties:
ShardCount: 1
IdentityPool:
Type: "AWS::Cognito::IdentityPool"
Properties:
IdentityPoolName: WorkshopIdentityPool
AllowUnauthenticatedIdentities: true
CognitoAuthorizedRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Federated: "cognito-identity.amazonaws.com"
Action:
- "sts:AssumeRoleWithWebIdentity"
Condition:
StringEquals:
"cognito-identity.amazonaws.com:aud":
Ref: IdentityPool
"ForAnyValue:StringLike":
"cognito-identity.amazonaws.com:amr": authenticated
Policies:
- PolicyName: "CognitoAuthorizedPolicy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action:
- "mobileanalytics:PutEvents"
- "cognito-sync:*"
Resource: "*"
CognitoUnAuthorizedRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Federated: "cognito-identity.amazonaws.com"
Action:
- "sts:AssumeRoleWithWebIdentity"
Condition:
StringEquals:
"cognito-identity.amazonaws.com:aud":
Ref: IdentityPool
"ForAnyValue:StringLike":
"cognito-identity.amazonaws.com:amr": unauthenticated
Policies:
- PolicyName: "CognitoUnauthorizedPolicy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action:
- "kinesis:PutRecords"
Resource:
Fn::GetAtt:
- WorkshopKinesisStream
- Arn
IdentityPoolRoleMapping:
Type: "AWS::Cognito::IdentityPoolRoleAttachment"
Properties:
IdentityPoolId:
Ref: IdentityPool
Roles:
authenticated:
Fn::GetAtt:
- CognitoAuthorizedRole
- Arn
unauthenticated:
Fn::GetAtt:
- CognitoUnAuthorizedRole
- Arn
Outputs:
IdentityPoolId:
Value:
Ref: IdentityPool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment