There are more AWS SDK examples available in the AWS Doc SDK Examples
Amazon WorkMail examples using AWS CLI
The following code examples show you how to perform actions and implement common scenarios by using the AWS Command Line Interface with Amazon WorkMail.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Actions
The following code example shows how to use associate-delegate-to-resource.
- AWS CLI
-
To add a delegate to a resource
The following
associate-delegate-to-resourcecommand adds a delegate to a resource.aws workmail associate-delegate-to-resource \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --resource-idr-68bf2d3b1c0244aab7264c24b9217443\ --entity-idS-1-1-11-1111111111-2222222222-3333333333-3333This command produces no output.
-
For API details, see AssociateDelegateToResource
in AWS CLI Command Reference.
-
The following code example shows how to use associate-member-to-group.
- AWS CLI
-
To add a member to a group
The following
associate-member-to-groupcommand adds the specified member to a group.aws workmail associate-member-to-group \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --group-idS-1-1-11-1122222222-2222233333-3333334444-4444\ --member-idS-1-1-11-1111111111-2222222222-3333333333-3333This command produces no output.
-
For API details, see AssociateMemberToGroup
in AWS CLI Command Reference.
-
The following code example shows how to use create-alias.
- AWS CLI
-
To create an alias
The following
create-aliascommand creates an alias for the specified entity (user or group).aws workmail create-alias \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --entity-idS-1-1-11-1122222222-2222233333-3333334444-4444\ --aliasexampleAlias@site.awsapps.comThis command produces no output.
-
For API details, see CreateAlias
in AWS CLI Command Reference.
-
The following code example shows how to use create-group.
- AWS CLI
-
To create a new group
The following
create-groupcommand creates a new group for the specified organization.aws workmail create-group \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --nameexampleGroup1Output:
{ "GroupId": "S-1-1-11-1122222222-2222233333-3333334444-4444" }-
For API details, see CreateGroup
in AWS CLI Command Reference.
-
The following code example shows how to use create-resource.
- AWS CLI
-
To create a new resource
The following
create-resourcecommand creates a new resource (meeting room) for the specified organization.aws workmail create-resource \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --nameexampleRoom1\ --typeROOMOutput:
{ "ResourceId": "r-7afe0efbade843a58cdc10251fce992c" }-
For API details, see CreateResource
in AWS CLI Command Reference.
-
The following code example shows how to use create-user.
- AWS CLI
-
To create a new user
The following
create-usercommand creates a new user.aws workmail create-user \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --nameexampleName\ --display-nameexampleDisplayName\ --passwordexamplePa$$w0rdOutput:
{ "UserId": "S-1-1-11-1111111111-2222222222-3333333333-3333" }-
For API details, see CreateUser
in AWS CLI Command Reference.
-
The following code example shows how to use delete-access-control-rule.
- AWS CLI
-
To delete an access control rule
The following
delete-access-control-ruleexample deletes the specified access control rule from the specified Amazon WorkMail organization.aws workmail delete-access-control-rule \ --organization-idm-n1pq2345678r901st2u3vx45x6789yza\ --name"myRule"This command produces no output.
For more information, see Working with Access Control Rules in the Amazon WorkMail Administrator Guide.
-
For API details, see DeleteAccessControlRule
in AWS CLI Command Reference.
-
The following code example shows how to use delete-alias.
- AWS CLI
-
To delete an alias
The following
delete-aliascommand deletes the alias for the specified entity (user or group).aws workmail delete-alias \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --entity-idS-1-1-11-1122222222-2222233333-3333334444-4444\ --aliasexampleAlias@site.awsapps.comThis command produces no output.
-
For API details, see DeleteAlias
in AWS CLI Command Reference.
-
The following code example shows how to use delete-group.
- AWS CLI
-
To delete an existing group
The following
delete-groupcommand deletes an existing group from Amazon WorkMail.aws workmail delete-group \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --group-idS-1-1-11-1122222222-2222233333-3333334444-4444This command produces no output.
-
For API details, see DeleteGroup
in AWS CLI Command Reference.
-
The following code example shows how to use delete-mailbox-permissions.
- AWS CLI
-
To delete mailbox permissions
The following
delete-mailbox-permissionscommand deletes mailbox permissions that were previously granted to a user or group. The entity represents the user that owns the mailbox, and the grantee represents the user or group for whom to delete permissions.aws workmail delete-mailbox-permissions \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --entity-idS-1-1-11-1122222222-2222233333-3333334444-4444\ --grantee-idS-1-1-11-1111111111-2222222222-3333333333-3333This command produces no output.
-
For API details, see DeleteMailboxPermissions
in AWS CLI Command Reference.
-
The following code example shows how to use delete-resource.
- AWS CLI
-
To delete an existing resource
The following
delete-resourcecommand deletes an existing resource from Amazon WorkMail.aws workmail delete-resource \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --resource-idr-7afe0efbade843a58cdc10251fce992cThis command produces no output.
-
For API details, see DeleteResource
in AWS CLI Command Reference.
-
The following code example shows how to use delete-user.
- AWS CLI
-
To delete a user
The following
delete-usercommand deletes the specified user from Amazon WorkMail and all subsequent systems.aws workmail delete-user \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --user-idS-1-1-11-1111111111-2222222222-3333333333-3333This command produces no output.
-
For API details, see DeleteUser
in AWS CLI Command Reference.
-
The following code example shows how to use deregister-from-work-mail.
- AWS CLI
-
To disable an existing entity
The following
deregister-from-work-mailcommand disables an existing entity (user, group, or resource) from using Amazon WorkMail.aws workmail deregister-from-work-mail \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --entity-idS-1-1-11-1111111111-2222222222-3333333333-3333This command produces no output.
-
For API details, see DeregisterFromWorkMail
in AWS CLI Command Reference.
-
The following code example shows how to use describe-group.
- AWS CLI
-
To retrieve information for a group
The following
describe-groupcommand retrieves information about the specified group.aws workmail describe-group \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --group-idS-1-1-11-1122222222-2222233333-3333334444-4444Output:
{ "GroupId": "S-1-1-11-1122222222-2222233333-3333334444-4444", "Name": "exampleGroup1", "State": "ENABLED" }-
For API details, see DescribeGroup
in AWS CLI Command Reference.
-
The following code example shows how to use describe-organization.
- AWS CLI
-
To retrieve information for an organization
The following
describe-organizationcommand retrieves information for the specified Amazon WorkMail organization.aws workmail describe-organization \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27Output:
{ "OrganizationId": "m-d281d0a2fd824be5b6cd3d3ce909fd27", "Alias": "alias", "State": "Active", "DirectoryId": "d-926726012c", "DirectoryType": "VpcDirectory", "DefaultMailDomain": "site.awsapps.com", "CompletedDate": 1522693605.468, "ARN": "arn:aws:workmail:us-west-2:111122223333:organization/m-n1pq2345678r901st2u3vx45x6789yza" }For more information, see Working with Organizations in the Amazon WorkMail Administrator Guide.
-
For API details, see DescribeOrganization
in AWS CLI Command Reference.
-
The following code example shows how to use describe-resource.
- AWS CLI
-
To retrieve information for a resource
The following
describe-resourcecommand retrieves information about the specified resource.aws workmail describe-resource \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --resource-idr-7afe0efbade843a58cdc10251fce992cOutput:
{ "ResourceId": "r-7afe0efbade843a58cdc10251fce992c", "Name": "exampleRoom1", "Type": "ROOM", "BookingOptions": { "AutoAcceptRequests": true, "AutoDeclineRecurringRequests": false, "AutoDeclineConflictingRequests": true }, "State": "ENABLED" }-
For API details, see DescribeResource
in AWS CLI Command Reference.
-
The following code example shows how to use describe-user.
- AWS CLI
-
To retrieve user information
The following
describe-usercommand retrieves information about the specified user.aws workmail describe-user \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --user-idS-1-1-11-1111111111-2222222222-3333333333-3333Output:
{ "UserId": "S-1-1-11-1111111111-2222222222-3333333333-3333", "Name": "exampleUser1", "Email": "exampleUser1@site.awsapps.com", "DisplayName": "", "State": "ENABLED", "UserRole": "USER", "EnabledDate": 1532459261.827 }-
For API details, see DescribeUser
in AWS CLI Command Reference.
-
The following code example shows how to use disassociate-delegate-from-resource.
- AWS CLI
-
To remove a member from a resource
The following
disassociate-delegate-from-resourcecommand removes the specified member from a resource.ws workmail disassociate-delegate-from-resource \ --organization-id m-d281d0a2fd824be5b6cd3d3ce909fd27 \ --resource-id r-68bf2d3b1c0244aab7264c24b9217443 \ --entity-id S-1-1-11-1111111111-2222222222-3333333333-3333This command produces no output.
-
For API details, see DisassociateDelegateFromResource
in AWS CLI Command Reference.
-
The following code example shows how to use disassociate-member-from-group.
- AWS CLI
-
To remove a member from a group
The following
disassociate-member-from-groupcommand removes the specified member from a group.aws workmail disassociate-member-from-group \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --group-idS-1-1-11-1122222222-2222233333-3333334444-4444\ --member-idS-1-1-11-1111111111-2222222222-3333333333-3333This command produces no output.
-
For API details, see DisassociateMemberFromGroup
in AWS CLI Command Reference.
-
The following code example shows how to use get-access-control-effect.
- AWS CLI
-
To get the effect of access control rules
The following
get-access-control-effectexample retrieves the effect of the specified Amazon WorkMail organization's access control rules for the specified IP address, access protocol action, and user ID.aws workmail get-access-control-effect \ --organization-idm-n1pq2345678r901st2u3vx45x6789yza\ --ip-address"192.0.2.0"\ --action"WindowsOutlook"\ --user-id"S-1-1-11-1111111111-2222222222-3333333333-3333"Output:
{ "Effect": "DENY", "MatchedRules": [ "myRule" ] }For more information, see Working with Access Control Rules in the Amazon WorkMail Administrator Guide.
-
For API details, see GetAccessControlEffect
in AWS CLI Command Reference.
-
The following code example shows how to use get-mailbox-details.
- AWS CLI
-
To get a user's mailbox details
The following
get-mailbox-detailscommand retrieves details about the specified user's mailbox.aws workmail get-mailbox-details \ --organization-idm-n1pq2345678r901st2u3vx45x6789yza\ --user-idS-1-1-11-1111111111-2222222222-3333333333-3333Output:
{ "MailboxQuota": 51200, "MailboxSize": 0.03890800476074219 }For more information, see Managing User Accounts in the Amazon WorkMail Administrator Guide.
-
For API details, see GetMailboxDetails
in AWS CLI Command Reference.
-
The following code example shows how to use list-access-control-rules.
- AWS CLI
-
To list access control rules
The following
list-access-control-rulesexample lists the access control rules for the specified Amazon WorkMail organization.aws workmail list-access-control-rules \ --organization-idm-n1pq2345678r901st2u3vx45x6789yzaOutput:
{ "Rules": [ { "Name": "default", "Effect": "ALLOW", "Description": "Default WorkMail Rule", "DateCreated": 0.0, "DateModified": 0.0 }, { "Name": "myRule", "Effect": "DENY", "Description": "my rule", "UserIds": [ "S-1-1-11-1111111111-2222222222-3333333333-3333" ], "DateCreated": 1581635628.0, "DateModified": 1581635628.0 } ] }For more information, see Working with Access Control Rules in the Amazon WorkMail Administrator Guide.
-
For API details, see ListAccessControlRules
in AWS CLI Command Reference.
-
The following code example shows how to use list-aliases.
- AWS CLI
-
To list aliases for a member
The following
list-aliasescommand lists aliases for the specified member (user or group).aws workmail list-aliases \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --entity-idS-1-1-11-1111111111-2222222222-3333333333-3333Output:
{ "Aliases": [ "exampleAlias@site.awsapps.com", "exampleAlias1@site.awsapps.com" ] }-
For API details, see ListAliases
in AWS CLI Command Reference.
-
The following code example shows how to use list-group-members.
- AWS CLI
-
To list group members
The following
list-group-memberscommand lists the members of the specified group.aws workmail list-group-members \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --group-idS-1-1-11-1122222222-2222233333-3333334444-4444Output:
{ "Members": [ { "Id": "S-1-1-11-1111111111-2222222222-3333333333-3333", "Name": "exampleUser1", "Type": "USER", "State": "ENABLED", "EnabledDate": 1532459261.827 } ] }-
For API details, see ListGroupMembers
in AWS CLI Command Reference.
-
The following code example shows how to use list-groups.
- AWS CLI
-
To retrieve a list of groups
The following
list-groupscommand retrieves summaries of the groups in the specified organization.aws workmail list-groups \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27Output:
{ "Groups": [ { "Id": "S-1-1-11-1122222222-2222233333-3333334444-4444", "Name": "exampleGroup1", "State": "DISABLED" }, { "Id": "S-4-4-44-1122222222-2222233333-3333334444-4444", "Name": "exampleGroup2", "State": "ENABLED" } ] }-
For API details, see ListGroups
in AWS CLI Command Reference.
-
The following code example shows how to use list-mailbox-permissions.
- AWS CLI
-
To retrieve mailbox permissions
The following
list-mailbox-permissionscommand retrieves the mailbox permissions associated with the specified entity's mailbox.aws workmail list-mailbox-permissions \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --entity-idS-1-1-11-1111111111-2222222222-3333333333-3333Output:
{ "Permissions": [ { "GranteeId": "S-1-1-11-1122222222-2222233333-3333334444-4444", "GranteeType": "USER", "PermissionValues": [ "FULL_ACCESS" ] } ] }-
For API details, see ListMailboxPermissions
in AWS CLI Command Reference.
-
The following code example shows how to use list-organizations.
- AWS CLI
-
To retrieve a list of organizations
The following
list-organizationscommand retrieves summaries of the customer's organizations.aws workmail list-organizationsOutput:
{ "OrganizationSummaries": [ { "OrganizationId": "m-d281d0a2fd824be5b6cd3d3ce909fd27", "Alias": "exampleAlias", "State": "Active" } ] }-
For API details, see ListOrganizations
in AWS CLI Command Reference.
-
The following code example shows how to use list-resource-delegates.
- AWS CLI
-
To list the delegates for a resource
The following
list-resource-delegatescommand retrieves the delegates associated with the specified resource.aws workmail list-resource-delegates \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --resource-idr-68bf2d3b1c0244aab7264c24b9217443Output:
{ "Delegates": [ { "Id": "S-1-1-11-1111111111-2222222222-3333333333-3333", "Type": "USER" } ] }-
For API details, see ListResourceDelegates
in AWS CLI Command Reference.
-
The following code example shows how to use list-resources.
- AWS CLI
-
To retrieve a list of resources
The following
list-resourcescommand retrieves summaries of the resources for the specified organization.aws workmail list-resources \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27Output:
{ "Resources": [ { "Id": "r-7afe0efbade843a58cdc10251fce992c", "Name": "exampleRoom1", "Type": "ROOM", "State": "ENABLED" } ] }-
For API details, see ListResources
in AWS CLI Command Reference.
-
The following code example shows how to use list-tags-for-resource.
- AWS CLI
-
To list the tags for a resource
The following
list-tags-for-resourceexample lists the tags for the specified Amazon WorkMail organization.aws workmail list-tags-for-resource \ --resource-arnarn:aws:workmail:us-west-2:111122223333:organization/m-n1pq2345678r901st2u3vx45x6789yzaOutput:
{ "Tags": [ { "Key": "priority", "Value": "1" } ] }For more information, see Tagging an Organization in the Amazon WorkMail Administrator Guide.
-
For API details, see ListTagsForResource
in AWS CLI Command Reference.
-
The following code example shows how to use list-users.
- AWS CLI
-
To retrieve a list of users
The following
list-userscommand retrieves summaries of the users in the specified organization.aws workmail list-users \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27Output:
{ "Users": [ { "Id": "S-1-1-11-1111111111-2222222222-3333333333-3333", "Email": "exampleUser1@site.awsapps.com", "Name": "exampleUser1", "State": "ENABLED", "UserRole": "USER", "EnabledDate": 1532459261.827 }, { "Id": "S-1-1-11-1122222222-2222233333-3333334444-4444", "Name": "exampleGuestUser", "State": "DISABLED", "UserRole": "SYSTEM_USER" } ] }-
For API details, see ListUsers
in AWS CLI Command Reference.
-
The following code example shows how to use put-access-control-rule.
- AWS CLI
-
To put a new access control rule
The following
put-access-control-ruleexample denies the specified user access to the specified Amazon WorkMail organization.aws workmail put-access-control-rule \ --name"myRule"\ --effect"DENY"\ --description"my rule"\ --user-ids"S-1-1-11-1111111111-2222222222-3333333333-3333"\ --organization-idm-n1pq2345678r901st2u3vx45x6789yzaThis command produces no output.
For more information, see Working with Access Control Rules in the Amazon WorkMail Administrator Guide.
-
For API details, see PutAccessControlRule
in AWS CLI Command Reference.
-
The following code example shows how to use put-mailbox-permissions.
- AWS CLI
-
To set mailbox permissions
The following
put-mailbox-permissionscommand sets full access permissions for the specified grantee (user or group). The entity represents the owner of the mailbox.aws workmail put-mailbox-permissions \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --entity-idS-1-1-11-1111111111-2222222222-3333333333-3333\ --grantee-idS-1-1-11-1122222222-2222233333-3333334444-4444\ --permission-valuesFULL_ACCESSThis command produces no output.
-
For API details, see PutMailboxPermissions
in AWS CLI Command Reference.
-
The following code example shows how to use register-to-work-mail.
- AWS CLI
-
To register an existing or disabled entity
The following
register-to-work-mailcommand enables the specified existing entity (user, group, or resource) to use Amazon WorkMail.aws workmail register-to-work-mail \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --entity-idS-1-1-11-1122222222-2222233333-3333334444-4444\ --emailexampleGroup1@site.awsapps.comThis command produces no output.
-
For API details, see RegisterToWorkMail
in AWS CLI Command Reference.
-
The following code example shows how to use reset-password.
- AWS CLI
-
To reset a user's password
The following
reset-passwordcommand resets the password for the specified user.aws workmail reset-password \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --user-idS-1-1-11-1111111111-2222222222-3333333333-3333\ --passwordexamplePa$$w0rdThis command produces no output.
-
For API details, see ResetPassword
in AWS CLI Command Reference.
-
The following code example shows how to use tag-resource.
- AWS CLI
-
To apply a tag to a resource
The following
tag-resourceexample applies a tag with key "priority" and value "1" to the specified Amazon WorkMail organization.aws workmail tag-resource \ --resource-arnarn:aws:workmail:us-west-2:111122223333:organization/m-n1pq2345678r901st2u3vx45x6789yza\ --tags"Key=priority,Value=1"This command produces no output.
For more information, see Tagging an Organization in the Amazon WorkMail Administrator Guide.
-
For API details, see TagResource
in AWS CLI Command Reference.
-
The following code example shows how to use untag-resource.
- AWS CLI
-
To untag a resource
The following
untag-resourceexample removes the specified tag from the specified Amazon WorkMail organization.aws workmail untag-resource \ --resource-arnarn:aws:workmail:us-west-2:111122223333:organization/m-n1pq2345678r901st2u3vx45x6789yza\ --tag-keys"priority"This command produces no output.
For more information, see Tagging an Organization in the Amazon WorkMail Administrator Guide.
-
For API details, see UntagResource
in AWS CLI Command Reference.
-
The following code example shows how to use update-mailbox-quota.
- AWS CLI
-
To update a user's mailbox quota
The following
update-mailbox-quotacommand changes the specified user's mailbox quota.aws workmail update-mailbox-quota \ --organization-idm-n1pq2345678r901st2u3vx45x6789yza\ --user-idS-1-1-11-1111111111-2222222222-3333333333-3333\ --mailbox-quota40000This command produces no output.
For more information, see Managing User Accounts in the Amazon WorkMail Administrator Guide.
-
For API details, see UpdateMailboxQuota
in AWS CLI Command Reference.
-
The following code example shows how to use update-primary-email-address.
- AWS CLI
-
To update a primary email address
The following
update-primary-email-addresscommand updates the primary email address of the specified entity (user, group, or resource).aws workmail update-primary-email-address \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --entity-idS-1-1-11-1111111111-2222222222-3333333333-3333\ --emailexampleUser2@site.awsapps.comThis command produces no output.
-
For API details, see UpdatePrimaryEmailAddress
in AWS CLI Command Reference.
-
The following code example shows how to use update-resource.
- AWS CLI
-
To update a resource
The following
update-resourcecommand updates the name of the specified resource.aws workmail update-resource \ --organization-idm-d281d0a2fd824be5b6cd3d3ce909fd27\ --resource-idr-7afe0efbade843a58cdc10251fce992c\ --nameexampleRoom2This command produces no output.
-
For API details, see UpdateResource
in AWS CLI Command Reference.
-