Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(aws-cdk-readme): replace deprecated method used in aws-chatbot README.md #13521

Merged
merged 2 commits into from
Mar 12, 2021

Conversation

BLasan
Copy link
Contributor

@BLasan BLasan commented Mar 10, 2021

Currently addLambdaInvokeCommandPermissions method used to get the permissions,
which is a deprecated method now.
Use addToPolicy method to get necessary permissions

fix: #13444


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Mar 10, 2021

@mergify
Copy link
Contributor

mergify bot commented Mar 10, 2021

Title does not follow the guidelines of Conventional Commits. Please adjust title before merge.

@BLasan BLasan changed the title Replace deprecated method addLambdaInvokeCommandPermissions with addToPolicy fix: deprecated method addLambdaInvokeCommandPermissions Mar 10, 2021
@BLasan BLasan force-pushed the issue-13444 branch 3 times, most recently from 0f547f8 to baf1ee4 Compare March 10, 2021 11:38
@BLasan BLasan changed the title fix: deprecated method addLambdaInvokeCommandPermissions chore(aws-cdk-readme): replace deprecated method used in aws-chatbot README.md Mar 10, 2021
@github-actions github-actions bot added the @aws-cdk/aws-chatbot Related to AWS Chatbot label Mar 10, 2021
Comment on lines 44 to 46
slackChannel.addNotificationPermissions();
slackChannel.addSupportCommandPermissions();
slackChannel.addReadOnlyCommandPermissions();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove these lines as the are also deprecated.

Comment on lines 37 to 41
const invokeCommandStatement = new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
resources: ["RESOURCE_ARNS_ALLOWED"],
actions: ["INVOKING_ACTION_ALLOWED"],
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can document this clearer and encourage a more idiomatic usage with the grantX methods on corresponding resources. IE, if we change this to.

const lambdaFn = new lambda.Function(this, 'MyChatbotHandler', {
  code: lambda.Code.fromAsset('./code'),
  runtime: lambda.Runtime.NODE_JS_14_X,
});
lambdaFn.grantInvoke(slackChannel.role);

@BLasan do you agree?

Copy link
Contributor Author

@BLasan BLasan Mar 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yuh, I think this would be ideal. But we need to add the permissions to the role first right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so lambdaFn.grantInvoke(slackChannel.role); should handle all of that. This should be the only grant statement needed for the chatbot to invoke the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

slackChannel.addLambdaInvokeCommandPermissions();
const invokeCommandStatement = new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
resources: ["RESOURCE_ARNS_ALLOWED"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NitPick: use single quotes to match the general repo style. (I prefer double but what can ya do 🤷🏻‍♂️ )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad. Will change this :)

@mergify mergify bot dismissed MrArnoldPalmer’s stale review March 11, 2021 19:16

Pull request has been modified.

@BLasan
Copy link
Contributor Author

BLasan commented Mar 11, 2021

@MrArnoldPalmer Updated

Comment on lines 38 to 43
const invokeCommandStatement = new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
resources: ['RESOURCE_ARNS_ALLOWED'],
actions: ['INVOKING_ACTION_ALLOWED'],
});

slackChannel.addToRolePolicy(invokeCommandStatement);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the lambda grant invoke removes the need for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MrArnoldPalmer Updated. please review

@mergify mergify bot dismissed MrArnoldPalmer’s stale review March 11, 2021 19:32

Pull request has been modified.

Comment on lines 46 to 51
const lambdaFn = new lambda.Function(this, 'MyChatbotHandler', {
code: lambda.Code.fromAsset('./code'),
runtime: lambda.Runtime.NODE_JS_14_X,
handler: 'FILE_NAME.handler',
});
lambdaFn.grantInvoke(slackChannel.role)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I'm not sure if this is needed here. I misinterpreted the point of the previous calls I believe. I'm not sure if addLambdaInvokeCommandPermissions is actually meant to grant access to a single specific lambda function. These aren't managed policies but just templates that the chatbot console will create a role with.

Perhaps we should just remove the usage of the methods that don't exist for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yuh, that method is for granting permissions in order to access a particular lambda function. Should we remove this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah lets remove this and the only changes from the original will be removing the calls to the deprecated methods. I do think users should be granting access to specific lambdas, cloudwatch metrics, etc and not using * resources. This however should be demonstrated in a more specific example.

@mergify mergify bot dismissed MrArnoldPalmer’s stale review March 11, 2021 20:04

Pull request has been modified.

@BLasan
Copy link
Contributor Author

BLasan commented Mar 11, 2021

@MrArnoldPalmer Looks good?

Comment on lines 37 to 43
const invokeCommandStatement = new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
resources: ['RESOURCE_ARNS_ALLOWED'],
actions: ['INVOKING_ACTION_ALLOWED'],
});

slackChannel.addToRolePolicy(invokeCommandStatement);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove this as well. If you want to include examples about adding template policies, it should be done in a separate snippet with corresponding documentation in a different PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will remove this as well :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MrArnoldPalmer Made the requested changes. Please review

…README.md

Currently addLambdaInvokeCommandPermissions method used to get the permissions,
which is a deprecated method now.
Use addToPolicy method to get necessary permissions.
@mergify mergify bot dismissed MrArnoldPalmer’s stale review March 11, 2021 20:14

Pull request has been modified.

MrArnoldPalmer
MrArnoldPalmer previously approved these changes Mar 11, 2021
@mergify mergify bot dismissed MrArnoldPalmer’s stale review March 12, 2021 10:11

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 3fddf76
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Mar 12, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 4769b31 into aws:master Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-chatbot Related to AWS Chatbot
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws-chatbot: addXXXPermisions() does not work
4 participants