Skip to content

Instantly share code, notes, and snippets.

@leantorres73
Created January 14, 2021 15:31
Show Gist options
  • Save leantorres73/a04620e3e079aa11a5562455291cd803 to your computer and use it in GitHub Desktop.
Save leantorres73/a04620e3e079aa11a5562455291cd803 to your computer and use it in GitHub Desktop.
Policy
const authRole = iam.Role.fromRoleArn(this, 'AuthRole', `arn:aws:iam::${Stack.of(this).region}:${Stack.of(this).account}:role/CognitoDefaultAuthenticatedRole`);
// Policy for Cognito invoking API Gateway
new iam.Policy(this, `${repositoryName}-Policy`, {
policyName: `${repositoryName}-Policy`,
roles: [authRole],
statements: [
new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
resources: [
`arn:aws:execute-api:${Stack.of(this).region}:${Stack.of(this).account}:${apigatewaysocket.ref}/*/$connect`
],
actions: [
'execute-api:Invoke'
]
}),
new iam.PolicyStatement({
effect: iam.Effect.DENY,
resources: [
`arn:aws:execute-api:${Stack.of(this).region}:${Stack.of(this).account}:${apigatewaysocket.ref}/*/secret`
],
actions: [
'execute-api:Invoke'
]
}),
new iam.PolicyStatement({
effect: iam.Effect.DENY,
resources: [
`arn:aws:execute-api:${Stack.of(this).region}:${Stack.of(this).account}:${apigatewaysocket.ref}/*`
],
actions: [
'execute-api:ManageConnections'
]
})
]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment