Identity-based policy examples for Amazon Lex V2 - Amazon Lex

Identity-based policy examples for Amazon Lex V2

By default, users and roles don't have permission to create or modify Amazon Lex V2 resources. They also can't perform tasks by using the AWS Management Console, AWS Command Line Interface (AWS CLI), or AWS API. To grant users permission to perform actions on the resources that they need, an IAM administrator can create IAM policies. The administrator can then add the IAM policies to roles, and users can assume the roles.

To learn how to create an IAM identity-based policy by using these example JSON policy documents, see Create IAM policies (console) in the IAM User Guide.

For details about actions and resource types defined by Amazon Lex V2, including the format of the ARNs for each of the resource types, see Actions, resources, and condition keys for Amazon Lex V2 in the Service Authorization Reference.

Policy best practices

Identity-based policies determine whether someone can create, access, or delete Amazon Lex V2 resources in your account. These actions can incur costs for your AWS account. When you create or edit identity-based policies, follow these guidelines and recommendations:

  • Get started with AWS managed policies and move toward least-privilege permissions – To get started granting permissions to your users and workloads, use the AWS managed policies that grant permissions for many common use cases. They are available in your AWS account. We recommend that you reduce permissions further by defining AWS customer managed policies that are specific to your use cases. For more information, see AWS managed policies or AWS managed policies for job functions in the IAM User Guide.

  • Apply least-privilege permissions – When you set permissions with IAM policies, grant only the permissions required to perform a task. You do this by defining the actions that can be taken on specific resources under specific conditions, also known as least-privilege permissions. For more information about using IAM to apply permissions, see Policies and permissions in IAM in the IAM User Guide.

  • Use conditions in IAM policies to further restrict access – You can add a condition to your policies to limit access to actions and resources. For example, you can write a policy condition to specify that all requests must be sent using SSL. You can also use conditions to grant access to service actions if they are used through a specific AWS service, such as AWS CloudFormation. For more information, see IAM JSON policy elements: Condition in the IAM User Guide.

  • Use IAM Access Analyzer to validate your IAM policies to ensure secure and functional permissions – IAM Access Analyzer validates new and existing policies so that the policies adhere to the IAM policy language (JSON) and IAM best practices. IAM Access Analyzer provides more than 100 policy checks and actionable recommendations to help you author secure and functional policies. For more information, see Validate policies with IAM Access Analyzer in the IAM User Guide.

  • Require multi-factor authentication (MFA) – If you have a scenario that requires IAM users or a root user in your AWS account, turn on MFA for additional security. To require MFA when API operations are called, add MFA conditions to your policies. For more information, see Secure API access with MFA in the IAM User Guide.

For more information about best practices in IAM, see Security best practices in IAM in the IAM User Guide.

Using the Amazon Lex V2 console

To access the Amazon Lex V2 console, you must have a minimum set of permissions. These permissions must allow you to list and view details about the Amazon Lex V2 resources in your AWS account. If you create an identity-based policy that is more restrictive than the minimum required permissions, the console won't function as intended for entities (users or roles) with that policy.

You don't need to allow minimum console permissions for users that are making calls only to the AWS CLI or the AWS API. Instead, allow access to only the actions that match the API operation that they're trying to perform.

To ensure that users and roles can still use the Amazon Lex V2 console, users need to have Console access. For more information about creating a user with Console access, see Creating an IAM user in your AWS account in the IAM User Guide.

Allow users to add functions to a bot

This example shows a policy that allows IAM users to add Amazon Comprehend, sentiment analysis and Amazon Kendra query permissions to an Amazon Lex V2 bot.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "Id1", "Effect": "Allow", "Action": "iam:PutRolePolicy", "Resource": "arn:aws:iam::*:role/aws-service-role/lexv2.amazonaws.com/AWSServiceRoleForLexV2Bots*" }, { "Sid": "Id2", "Effect": "Allow", "Action": "iam:GetRolePolicy", "Resource": "arn:aws:iam::*:role/aws-service-role/lexv2.amazonaws.com/AWSServiceRoleForLexV2Bots*" } ] }

Allow users to add channels to a bot

This example is a policy that allows IAM users to add a messaging channel to a bot. A user must have this policy in place before they can deploy a bot on a messaging platform.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "Id1", "Effect": "Allow", "Action": "iam:PutRolePolicy", "Resource": "arn:aws:iam::*:role/aws-service-role/channels.lexv2.amazonaws.com/AWSServiceRoleForLexV2Channels*" }, { "Sid": "Id2", "Effect": "Allow", "Action": "iam:GetRolePolicy", "Resource": "arn:aws:iam::*:role/aws-service-role/channels.lexv2.amazonaws.com/AWSServiceRoleForLexV2Channels*" } ] }

Allow users to create and update bots

This example shows an example policy that allows IAM users to create and update any bot. The policy includes permissions to complete this action on the console or using the AWS CLI or AWS API.

{ "Version": "2012-10-17", "Statement": [ { "Action": [ "lex:CreateBot", "lex:UpdateBot". "iam:PassRole" ], "Effect": "Allow", "Resource": ["arn:aws:lex:Region:123412341234:bot/*] } ] }

Allow users to use the Automated Chatbot Designer

This example shows an example policy that allows IAM users to run the Automated Chatbot Designer.

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:GetObject", "s3:ListBucket" ], "Resource": [ "arn:aws:s3:::<customer-bucket>/<bucketName>", # Resource should point to the bucket or an explicit folder. # Provide this to read the entire bucket "arn:aws:s3:::<customer-bucket>/<bucketName>/*", # Provide this to read a specifc folder "arn:aws:s3:::<customer-bucket>/<bucketName>/<pathFormat>/*" ] }, { # Use this if your S3 bucket is encrypted with a KMS key. "Effect": "Allow", "Action": [ "kms:Decrypt" ], "Resource": [ "arn:aws:kms:<Region>:<customerAccountId>:key/<kmsKeyId>" ] ] }

Allow users to use a AWS KMS key to encrypt and decrypt files

This example shows an example policy that allows IAM users to use a AWS KMS customer managed key to encrypt and decrypt data.

{ "Version": "2012-10-17", "Id": "sample-policy", "Statement": [ { "Sid": "Allow Lex access", "Effect": "Allow", "Principal": { "Service": "lexv2.amazonaws.com" }, "Action": [ # If the key is for encryption "kms:Encrypt", "kms:GenerateDataKey" # If the key is for decryption "kms:Decrypt" ], "Resource": "*" } ] }

Allow users to delete bots

This example shows an example policy that allows IAM users to delete any bot. The policy includes permissions to complete this action on the console or using the AWS CLI or AWS API.

{ "Version": "2012-10-17", "Statement": [ { "Action": [ "lex:DeleteBot", "lex:DeleteBotLocale", "lex:DeleteBotAlias", "lex:DeleteIntent", "lex:DeleteSlot", "lex:DeleteSlottype" ], "Effect": "Allow", "Resource": ["arn:aws:lex:Region:123412341234:bot/*", "arn:aws:lex:Region:123412341234:bot-alias/*"] } ] }

Allow users to have a conversation with a bot

This example shows an example policy that allows IAM users have a conversation with any bot. The policy includes permissions to complete this action on the console or using the AWS CLI or AWS API.

{ "Version": "2012-10-17", "Statement": [ { "Action": [ "lex:StartConversation", "lex:RecognizeText", "lex:RecognizeUtterance", "lex:GetSession", "lex:PutSession", "lex:DeleteSession" ], "Effect": "Allow", "Resource": "arn:aws:lex:Region:123412341234:bot-alias/*" } ] }

Allow a specific user to manage resource-based policies

The following example grants permission for a specific user to manage the resource-based policies. It allows console and API access to the policies associated with bots and bot aliases.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "ResourcePolicyEditor", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::123456789012:role/ResourcePolicyEditor" }, "Action": [ "lex:CreateResourcePolicy", "lex:UpdateResourcePolicy", "lex:DeleteResourcePolicy", "lex:DescribeResourcePolicy" ] } ] }

Allow a user to export bots and bot locales

The following IAM permission policy enables a user to create, update, and get an export for a bot or bot locale.

{ "Version": "2012-10-17", "Statement": [ { "Action": [ "lex:CreateExport", "lex:UpdateExport", "lex:DescribeExport", "lex:DescribeBot", "lex:DescribeBotLocale", "lex:ListBotLocales", "lex:DescribeIntent", "lex:ListIntents", "lex:DescribeSlotType", "lex:ListSlotTypes", "lex:DescribeSlot", "lex:ListSlots", "lex:DescribeCustomVocabulary" ], "Effect": "Allow", "Resource": ["arn:aws:lex:Region:123456789012:bot/*"] } ] }

Allow a user to export a custom vocabulary

The following IAM permission policy allows a user to export a custom vocabulary from a bot locale.

{"Version": "2012-10-17", "Statement": [ {"Action": [ "lex:CreateExport", "lex:UpdateExport", "lex:DescribeExport", "lex:DescribeCustomVocabulary" ], "Effect": "Allow", "Resource": ["arn:aws:lex:Region:123456789012:bot/*"] } ] }

Allow a user to import bots and bot locales

The following IAM permission policy allows a user to import a bot or bot locale and to check the status of an import.

{ "Version": "2012-10-17", "Statement": [ { "Action": [ "lex:CreateUploadUrl", "lex:StartImport", "lex:DescribeImport", "lex:CreateBot", "lex:UpdateBot", "lex:DeleteBot", "lex:CreateBotLocale", "lex:UpdateBotLocale", "lex:DeleteBotLocale", "lex:CreateIntent", "lex:UpdateIntent", "lex:DeleteIntent", "lex:CreateSlotType", "lex:UpdateSlotType", "lex:DeleteSlotType", "lex:CreateSlot", "lex:UpdateSlot", "lex:DeleteSlot", "lex:CreateCustomVocabulary", "lex:UpdateCustomVocabulary", "lex:DeleteCustomVocabulary", "iam:PassRole", ], "Effect": "Allow", "Resource": [ "arn:aws:lex:Region:123456789012:bot/*", "arn:aws:lex:Region:123456789012:bot-alias/*" ] } ] }

Allow a user to import a custom vocabulary

The following IAM permission policy allows a user to import a custom vocabulary to a bot locale.

{ "Version": "2012-10-17", "Statement": [ { "Action": [ "lex:CreateUploadUrl", "lex:StartImport", "lex:DescribeImport", "lex:CreateCustomVocabulary", "lex:UpdateCustomVocabulary", "lex:DeleteCustomVocabulary" ], "Effect": "Allow", "Resource": [ "arn:aws:lex:Region:123456789012:bot/*" ] } ] }

Allow a user to migrate a bot from Amazon Lex to Amazon Lex V2

The following IAM permission policy allows a user to start migrating a bot from Amazon Lex to Amazon Lex V2.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "startMigration", "Effect": "Allow", "Action": "lex:StartMigration", "Resource": "arn:aws:lex:>Region<:>123456789012<:bot:*" }, { "Sid": "passRole", "Effect": "Allow", "Action": "iam:PassRole", "Resource": "arn:aws:iam::>123456789012<:role/>v2 bot role<" }, { "Sid": "allowOperations", "Effect": "Allow", "Action": [ "lex:CreateBot", "lex:CreateIntent", "lex:UpdateSlot", "lex:DescribeBotLocale", "lex:UpdateBotAlias", "lex:CreateSlotType", "lex:DeleteBotLocale", "lex:DescribeBot", "lex:UpdateBotLocale", "lex:CreateSlot", "lex:DeleteSlot", "lex:UpdateBot", "lex:DeleteSlotType", "lex:DescribeBotAlias", "lex:CreateBotLocale", "lex:DeleteIntent", "lex:StartImport", "lex:UpdateSlotType", "lex:UpdateIntent", "lex:DescribeImport", "lex:CreateCustomVocabulary", "lex:UpdateCustomVocabulary", "lex:DeleteCustomvocabulary", "lex:DescribeCustomVocabulary", "lex:DescribeCustomVocabularyMetadata" ], "Resource": [ "arn:aws:lex:>Region<:>123456789012<:bot/*", "arn:aws:lex:>Region<:>123456789012<:bot-alias/*/*" ] }, { "Sid": "showBots", "Effect": "Allow", "Action": [ "lex:CreateUploadUrl", "lex:ListBots" ], "Resource": "*" } ] }

Allow users to view their own permissions

This example shows how you might create a policy that allows IAM users to view the inline and managed policies that are attached to their user identity. This policy includes permissions to complete this action on the console or programmatically using the AWS CLI or AWS API.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "ViewOwnUserInfo", "Effect": "Allow", "Action": [ "iam:GetUserPolicy", "iam:ListGroupsForUser", "iam:ListAttachedUserPolicies", "iam:ListUserPolicies", "iam:GetUser" ], "Resource": ["arn:aws:iam::*:user/${aws:username}"] }, { "Sid": "NavigateInConsole", "Effect": "Allow", "Action": [ "iam:GetGroupPolicy", "iam:GetPolicyVersion", "iam:GetPolicy", "iam:ListAttachedGroupPolicies", "iam:ListGroupPolicies", "iam:ListPolicyVersions", "iam:ListPolicies", "iam:ListUsers" ], "Resource": "*" } ] }

Allow a user to draw conversation flow with visual conversation builder in Amazon Lex V2

The following IAM permission policy allows a user to draw the conversation flow with visual conversation builder in Amazon Lex V2.

{ "Version": "2012-10-17", "Statement": [ {"Action": [ "lex:UpdateIntent ", "lex:DescribeIntent " ], "Effect": "Allow", "Resource": ["arn:aws:lex:Region:123456789012:bot/*"] } ] }

Allow users to create and view bot replicas, but not to delete them

You can attach the following permissions to an IAM role to allow it to only create and view bot replicas. By omitting lex:DeleteBotReplica, you prevent the role from deleting bot replicas. For more information, see Permissions to replicate bots and manage bot replicas in Lex V2.

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "lex:CreateBotReplica", "lex:DescribeBotReplica", "lex:ListBotReplica", "lex:ListBotVersionReplicas", "lex:ListBotAliasReplicas", ], "Resource": [ "arn:aws:lex:*:*:bot/*", "arn:aws:lex:*:*:bot-alias/*" ] }, { "Effect": "Allow", "Action": [ "iam:GetRole" ], "Resource": [ "arn:aws:iam::*:role/aws-service-role/replication.lexv2.amazonaws.com/AWSServiceRoleForLexV2Replication*" ] }, { "Effect": "Allow", "Action": [ "iam:CreateServiceLinkedRole", ], "Resource": [ "arn:aws:iam::*:role/aws-service-role/replication.lexv2.amazonaws.com/AWSServiceRoleForLexV2Replication*" ], "Condition": { "StringEquals": { "iam:AWSServiceName": "lexv2.amazonaws.com" } } } ] }