Workdocs DG
Workdocs DG
Developer Guide
Amazon WorkDocs Developer Guide
Amazon's trademarks and trade dress may not be used in connection with any product or service that is not
Amazon's, in any manner that is likely to cause confusion among customers, or in any manner that disparages or
discredits Amazon. All other trademarks not owned by Amazon are the property of their respective owners, who may
or may not be affiliated with, connected to, or sponsored by Amazon.
Amazon WorkDocs Developer Guide
Table of Contents
What is Amazon WorkDocs? ................................................................................................................ 1
Accessing .................................................................................................................................. 1
Pricing ...................................................................................................................................... 1
Resources .................................................................................................................................. 1
Getting started .................................................................................................................................. 3
Connect to Amazon WorkDocs with IAM user credentials ................................................................. 3
Connecting to Amazon WorkDocs by assuming a role ..................................................................... 4
Upload a document .................................................................................................................... 6
Download a document ................................................................................................................ 7
Setting up notifications for an IAM user or role ............................................................................. 7
Creating a user .......................................................................................................................... 9
Granting users permissions to a resource ..................................................................................... 10
Authentication and access control for administrative applications ........................................................... 11
Granting developers permissions to the Amazon WorkDocs API ...................................................... 11
Granting third-party developers permission to the Amazon WorkDocs APIs ...................................... 11
Granting users permission to assume an IAM role ......................................................................... 13
Restricting access to a specific Amazon WorkDocs instance ............................................................ 13
Authentication and access control for user applications ......................................................................... 14
Granting permissions to call the Amazon WorkDocs APIs ............................................................... 14
Using folder IDs in API calls ....................................................................................................... 15
Create an application ................................................................................................................ 16
Application scopes .................................................................................................................... 16
Authorization ........................................................................................................................... 17
Invoking Amazon WorkDocs APIs ................................................................................................ 18
Amazon WorkDocs Content Manager .................................................................................................. 19
Constructing Amazon WorkDocs Content Manager ....................................................................... 19
Downloading a document ......................................................................................................... 19
Uploading a document .............................................................................................................. 20
AWS glossary ................................................................................................................................... 22
iii
Amazon WorkDocs Developer Guide
Accessing
Users can share their files with other members of your organization for collaboration or review. The
Amazon WorkDocs client applications can be used to view many different types of files, depending
on the Internet media type of the file. Amazon WorkDocs supports all common document and image
formats, and support for additional media types is constantly being added.
Accessing
End users use the client applications to access their files. Non-administrative users never need to use the
Amazon WorkDocs console or the administration dashboard. Amazon WorkDocs offers several different
client applications and utilities:
Pricing
With Amazon WorkDocs, there are no upfront fees or commitments. You pay only for active user
accounts, and the storage you use. For more information, go to Pricing.
Resources
The following related resources can help you as you work with this service.
• Classes & Workshops – Links to role-based and specialty courses, in addition to self-paced labs to help
sharpen your AWS skills and gain practical experience.
• AWS Developer Tools – Links to developer tools, SDKs, IDE toolkits, and command line tools for
developing and managing AWS applications.
• AWS Whitepapers – Links to a comprehensive list of technical AWS whitepapers, covering topics such
as architecture, security, and economics and authored by AWS Solutions Architects or other technical
experts.
• AWS Support Center – The hub for creating and managing your AWS Support cases. Also includes
links to other helpful resources, such as forums, technical FAQs, service health status, and AWS Trusted
Advisor.
• AWS Support – The primary webpage for information about AWS Support, a one-on-one, fast-
response support channel to help you build and run applications in the cloud.
1
Amazon WorkDocs Developer Guide
Resources
• Contact Us – A central contact point for inquiries concerning AWS billing, account, events, abuse, and
other issues.
• AWS Site Terms – Detailed information about our copyright and trademark; your account, license, and
site access; and other topics.
2
Amazon WorkDocs Developer Guide
Connect to Amazon WorkDocs with IAM user credentials
Getting started
The following code snippets can help you get started using the Amazon WorkDocs SDK.
Examples
• Connect to Amazon WorkDocs with IAM user credentials and query for users (p. 3)
• Connecting to Amazon WorkDocs by assuming a role (p. 4)
• Upload a document (p. 6)
• Download a document (p. 7)
• Setting up notifications for an IAM user or role (p. 7)
• Creating a user (p. 9)
• Granting users permissions to a resource (p. 10)
Ensure that the IAM user has been granted Amazon WorkDocs API access through an appropriate IAM
policy.
The code sample uses the DescribeUsers API to search for users, and obtain metadata for users. User
metadata provides details such as first name, last name, User ID and Root Folder ID. Root Folder ID is
particularly helpful if you want to perform any content upload or download operations on behalf of the
user.
The code requires that you obtain an Amazon WorkDocs Organization ID.
Follow these steps to obtain a Amazon WorkDocs organization ID from the AWS console:
To get an organization ID
The example shows how to use IAM credentials to make API calls.
import java.util.ArrayList;
import java.util.List;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.workdocs.AmazonWorkDocs;
3
Amazon WorkDocs Developer Guide
Connecting to Amazon WorkDocs by assuming a role
import com.amazonaws.services.workdocs.AmazonWorkDocsClient;
import com.amazonaws.services.workdocs.model.DescribeUsersRequest;
import com.amazonaws.services.workdocs.model.DescribeUsersResult;
import com.amazonaws.services.workdocs.model.User;
AmazonWorkDocs workDocs =
AmazonWorkDocsClient.builder().withCredentials(staticCredentialProvider)
.withRegion(Regions.US_WEST_2).build();
import java.util.ArrayList;
import java.util.List;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.BasicSessionCredentials;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.securitytoken.AWSSecurityTokenService;
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClientBuilder;
4
Amazon WorkDocs Developer Guide
Connecting to Amazon WorkDocs by assuming a role
import com.amazonaws.services.securitytoken.model.AssumeRoleRequest;
import com.amazonaws.services.securitytoken.model.AssumeRoleResult;
import com.amazonaws.services.workdocs.AmazonWorkDocs;
import com.amazonaws.services.workdocs.AmazonWorkDocsClient;
import com.amazonaws.services.workdocs.model.DescribeFolderContentsRequest;
import com.amazonaws.services.workdocs.model.DescribeFolderContentsResult;
import com.amazonaws.services.workdocs.model.DocumentMetadata;
import com.amazonaws.services.workdocs.model.FolderMetadata;
AWSCredentials longTermCredentials =
new BasicAWSCredentials("accessKey", "secretKey");
// Use developer’s long-term credentials to call the AWS Security Token Service (STS)
// AssumeRole API, specifying the ARN for the role workdocs-readonly-role in
// 3rd party AWS account.
AWSSecurityTokenService stsClient =
AWSSecurityTokenServiceClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(longTermCredentials))
.withRegion(Regions.DEFAULT_REGION.getName()).build();;
BasicSessionCredentials temporaryCredentials =
new BasicSessionCredentials(assumeResult.getCredentials().getAccessKeyId(),
assumeResult
.getCredentials().getSecretAccessKey(),
assumeResult.getCredentials().getSessionToken());
describeFolder("root-folder-id");
}
5
Amazon WorkDocs Developer Guide
Upload a document
do {
request.setMarker(marker);
DescribeFolderContentsResult result = workDocs.describeFolderContents(request);
documents.addAll(result.getDocuments());
folders.addAll(result.getFolders());
marker = result.getMarker();
} while (marker != null);
Upload a document
Use the following procedure to upload a document to Amazon WorkDocs.
To upload a document
If you are using IAM user credentials, refer to Connect to Amazon WorkDocs with IAM user
credentials and query for users (p. 3). If you are assuming an IAM role, refer to Connecting to
Amazon WorkDocs by assuming a role (p. 4) for more details.
AWSCredentials longTermCredentials =
new BasicAWSCredentials("accessKey", "secretKey");
AWSStaticCredentialsProvider staticCredentialProvider =
new AWSStaticCredentialsProvider(longTermCredentials);
6
Amazon WorkDocs Developer Guide
Download a document
4. Complete the upload process by changing the document status to ACTIVE as follows:
Download a document
To download a document from Amazon WorkDocs, get a URL for the download as follows, and then use
the API actions provided by your development platform to download the file using the URL.
• Use the IAM console to set the following permissions for the user:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"workdocs:CreateNotificationSubscription",
"workdocs:DeleteNotificationSubscription",
"workdocs:DescribeNotificationSubscriptions"
],
"Resource": "*"
}
]
}
7
Amazon WorkDocs Developer Guide
Setting up notifications for an IAM user or role
To enable notifications
For information about enabling Amazon WorkDocs to use notifications, see Using the Amazon WorkDocs
API with the AWS SDK for Python and AWS Lambda. Once you enable notifications, you and your user
can subscribe to them.
1. Prepare your endpoint to process Amazon SNS messages. For more information, see Fanout to
HTTP/S endpoints in the Amazon Simple Notification Service Developer Guide.
Important
SNS sends a confirmation message to your configured endpoint. You must confirm
this message in order to receive notifications. Also, if you require FIPS 140-2 validated
cryptographic modules when accessing AWS through a command line interface or an API,
use a FIPS endpoint. For more information about the available FIPS endpoints, see Federal
Information Processing Standard (FIPS) 140-2.
2. Do the following:
• Get an organization ID
1. In the AWS Directory Service console navigation pane, select Directories.
2. The Directory ID corresponding to your Amazon WorkDocs site also serves as the Organization
ID for that site.
• Create the subscription request as follows:
SNS Notifications
8
Amazon WorkDocs Developer Guide
Creating a user
To disable notifications
Creating a user
The following code snippet demonstrates the request construction for creating a user in Amazon
WorkDocs.
Note
This is not a valid operation for a Connected AD configuration. To create a user in the Connected
AD configuration, the user must already be present in the enterprise directory. Then, you must
make a call to the ActivateUser API to activate the user in Amazon WorkDocs.
The following example demonstrates how to create a user with a storage quota of 1 gigabytes.
Follow these steps to obtain a Amazon WorkDocs organization ID from the AWS console:
To get an organization ID
9
Amazon WorkDocs Developer Guide
Granting users permissions to a resource
2. Note the Directory ID value that corresponds to your Amazon WorkDocs site. That is the
Organization ID for the site.
10
Amazon WorkDocs Developer Guide
Granting developers permissions
to the Amazon WorkDocs API
Tasks
• Granting developers permissions to the Amazon WorkDocs API (p. 11)
• Granting third-party developers permission to the Amazon WorkDocs APIs (p. 11)
• Granting users permission to assume an IAM role (p. 13)
• Restricting access to a specific Amazon WorkDocs instance (p. 13)
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "WorkDocsAPIReadOnly",
"Effect": "Allow",
"Action": [
"workdocs:Get*",
"workdocs:Describe*"
],
"Resource": [
"*"
]
}
]
}
11
Amazon WorkDocs Developer Guide
Granting third-party developers
permission to the Amazon WorkDocs APIs
• Developer belongs to the same organization but the developer’s AWS account is different from the
Amazon WorkDocs AWS account.
• When an enterprise would like to grant Amazon WorkDocs API access to third-party application
developers.
In both of these scenarios, there are two AWS accounts involved, a developer’s AWS account and a
different account hosting a Amazon WorkDocs site.
The developer will need to provide the following information so the account administrator can create the
IAM role:
The following procedure describes steps involved in configuring IAM for cross-account access.
a. Sign in to the AWS Management Console and open the IAM console at https://
console.aws.amazon.com/iam/.
b. In the navigation pane of the console, click Roles and then click Create New Role.
c. For Role name, type a role name to help identify the purpose of this role, for example
workdocs_app_role. Role names must be unique within your AWS account. After you enter
the name, click Next Step.
d. On the Select Role Type page, select the Role for Cross-Account Access section, and then
select the type of role that you want to create:
• Select Provide access between AWS accounts you own if you are the administrator of both
the user account and the resource account, or both accounts belong to the same company.
This is also the option to select when the users, role, and resource to be accessed are all in the
same account.
• Select Provide access between your AWS account and a third-party AWS account if you
are the administrator of the account that owns the Amazon WorkDocs site and you want to
grant permissions to users from an Application developer account. This option requires you
to specify an external ID (which the third party must provide to you) to provide additional
control over the circumstances in which the third party can use the role to access your
resources. For more information, see How to Use an External ID When Granting Access to Your
AWS Resources to a Third Party.
e. On the next page, specify the AWS account ID to which you want to grant access to your
resources and also enter External ID in case of third-party access.
f. Click Next Step to attach a policy.
3. On the Attach Policy page, search for the Amazon WorkDocs API permission policy that was created
earlier and select the box next to the policy and click Next Step.
4. Review the details, copy the role ARN for future reference and click Create Role to complete the
creation of the role.
12
Amazon WorkDocs Developer Guide
Granting users permission to assume an IAM role
5. Share the role ARN with the developer. The following is an example of the role ARN:
arn:aws:iam::AWS-ACCOUNT-ID:role/workdocs_app_role
The policy must include a statement with the Allow effect on the sts:AssumeRole action, plus the
Amazon Resource Name (ARN) of the role in a Resource element, as shown in the following example.
Users that get the policy, either through group membership or direct attachment, can switch to the
specified role.
{
"Version": "2012-10-17",
"Statement": {
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::<aws_account_id>:role/workdocs_app_role"
}
}
"Condition":
{
"StringEquals": {
"Resource.OrganizationId": "d-123456789c5"
}
}
With the above condition in place in a policy, users can only access the Amazon WorkDocs instance
with the ID of d-123456789c5. Amazon WorkDocs Instance ID is sometimes referred as Organization
ID or Directory ID. For more information, see Restricting access to a specific Amazon WorkDocs
instance (p. 13).
Follow these steps to obtain a Amazon WorkDocs organization ID from the AWS console:
To get an organization ID
13
Amazon WorkDocs Developer Guide
Granting permissions to call the Amazon WorkDocs APIs
Currently, applications can only access Amazon WorkDocs sites within the same AWS account where they
are registered.
Contents
• Granting permissions to call the Amazon WorkDocs APIs (p. 14)
• Using folder IDs in API calls (p. 15)
• Create an application (p. 16)
• Application scopes (p. 16)
• Authorization (p. 17)
• Invoking Amazon WorkDocs APIs (p. 18)
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"workdocs:*",
"ds:*",
"ec2:CreateVpc",
"ec2:CreateSubnet",
"ec2:CreateNetworkInterface",
"ec2:CreateTags",
"ec2:CreateSecurityGroup",
"ec2:DescribeVpcs",
"ec2:DescribeSubnets",
"ec2:DescribeNetworkInterfaces",
"ec2:DescribeAvailabilityZones",
"ec2:AuthorizeSecurityGroupEgress",
"ec2:AuthorizeSecurityGroupIngress",
"ec2:DeleteSecurityGroup",
"ec2:DeleteNetworkInterface",
"ec2:RevokeSecurityGroupEgress",
14
Amazon WorkDocs Developer Guide
Using folder IDs in API calls
"ec2:RevokeSecurityGroupIngress"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"workdocs:Describe*",
"ds:DescribeDirectories",
"ec2:DescribeVpcs",
"ec2:DescribeSubnets"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
In the policy, the first action grants access to all the Amazon WorkDocs Describe operations. The
DescribeDirectories action obtains information about your AWS Directory Service directories. The
Amazon EC2 operations enable Amazon WorkDocs to obtain a list of your VPCs and subnets.
client.get_folder(FolderId='MyDocs')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\user-name\AppData\Local\Programs\Python\Python36-32\lib\site-packages
\botocore\client.py", line 253, in _api_call
return self._make_api_call(operation_name, kwargs)
File "C:\Users\user-name\AppData\Local\Programs\Python\Python36-32\lib\site-packages
\botocore\client.py", line 557, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.UnauthorizedResourceAccessException: An error occurred
(UnauthorizedResourceAccessException) when calling the GetFolder operation:
Principal [arn:aws:iam::395162986870:user/Aman] is not allowed to execute
[workdocs:GetFolder] on the resource.
site.workdocs/index.html#/folder/
abc123def456ghi789jkl789mno4be7024df198736472dd50ca970eb22796082e3d489577.
client.get_folder(FolderId='abc123def456ghi789jkl789mno4be7024df198736472dd50ca970eb22796082e3d489577')
15
Amazon WorkDocs Developer Guide
Create an application
Create an application
As an Amazon WorkDocs administrator, create your application using the following steps.
To create an application
Application Name
The location that you want Amazon WorkDocs to redirect traffic to.
Application Scopes
The scope, either read or write, that you wish your application to have. For more details, see
Application scopes (p. 16).
4. Choose Create.
Application scopes
Amazon WorkDocs supports the following application scopes:
• Content Read (workdocs.content.read), which gives your application access to the following
Amazon WorkDocs APIs:
• Get*
• Describe*
• Content Write (workdocs.content.write), which gives your application access to the following
Amazon WorkDocs APIs:
• Create*
• Update*
16
Amazon WorkDocs Developer Guide
Authorization
• Delete*
• Initiate*
• Abort*
• Add*
• Remove*
Authorization
After application registration is complete, an application can request authorization on behalf of any
Amazon WorkDocs user. To do this, the application should visit the Amazon WorkDocs OAuth endpoint,
https://auth.amazonworkdocs.com/oauth, and provide the following query parameters:
Note
If you require FIPS 140-2 validated cryptographic modules when accessing AWS through
a command line interface or an API, use a FIPS endpoint. For more information about the
available FIPS endpoints, see Federal Information Processing Standard (FIPS) 140-2.
A sample GET request to initiate the OAuth flow to obtain an access token:
GET https://auth.amazonworkdocs.com/oauth?app_id=my-app-
id&auth_type=ImplicitGrant&redirect_uri=https://myapp.com/
callback&scopes=workdocs.content.read&state=xyz
1. The application user is prompted to enter the Amazon WorkDocs site name.
2. The user is redirected to the Amazon WorkDocs authentication page to enter their credentials.
3. After successful authentication, the user is presented with the consent screen that allows the user to
either grant or deny your application the authorization to access Amazon WorkDocs.
4. After the user chooses Accept on the consent screen, their browser is redirected to your
application's callback URL along with the access token and region information as query parameters.
GET https://myapp.com/callback?acessToken=accesstoken®ion=us-east-1&state=xyz
In addition to the access token, the Amazon WorkDocs OAuth service also returns region as a query
parameter for the selected Amazon WorkDocs site. External applications should use the region
parameter to determine the Amazon WorkDocs service endpoint.
If you require FIPS 140-2 validated cryptographic modules when accessing AWS through a command line
interface or an API, use a FIPS endpoint. For more information about the available FIPS endpoints, see
Federal Information Processing Standard (FIPS) 140-2.
17
Amazon WorkDocs Developer Guide
Invoking Amazon WorkDocs APIs
This example shows how to use a curl GET request to obtain a document's metadata.
@Override
public AWSCredentials getCredentials() {
new AnonymousAWSCredentials();
}
};
18
Amazon WorkDocs Developer Guide
Constructing Amazon WorkDocs Content Manager
Topics
• Constructing Amazon WorkDocs Content Manager (p. 19)
• Downloading a document (p. 19)
• Uploading a document (p. 20)
For user applications, a developer must construct Amazon WorkDocs Content Manager with anonymous
AWS credentials and an authentication token.
For administrative applications, the Amazon WorkDocs client must be initialized with AWS Identity
and Access Management (IAM) credentials. In addition, the authentication token must be omitted in
subsequent API calls.
The following code demonstrates how to initialize Amazon WorkDocs Content Manager for user
applications using Java or C#.
Java:
AmazonWorkDocs client =
AmazonWorkDocsClient.builder().withCredentials(credentialsProvider).withRegion("region").build();
ContentManager contentManager =
ContentManagerBuilder.standard().withWorkDocsClient(client).withAuthenticationToken("token").build();
C#:
Downloading a document
Developers can use Amazon WorkDocs Content Manager to download a specific version or the latest
version of a document from Amazon WorkDocs. The following examples demonstrate how to download
a specific version of a document using Java and C#.
19
Amazon WorkDocs Developer Guide
Uploading a document
Note
To download the latest version of a document, do not specify the VersionId when
constructing the GetDocumentStream request.
Java
ContentManager contentManager =
ContentManagerBuilder.standard().withWorkDocsClient(client).withAuthenticationToken("auth-
token").build();
// Download document.
GetDocumentStreamRequest request = new GetDocumentStreamRequest();
request.setDocumentId("document-id");
request.setVersionId("version-id");
C#
ContentManager contentManager =
ContentManagerBuilder.standard().withWorkDocsClient(client).withAuthenticationToken("auth-
token").build();
// Download document.
GetDocumentStreamRequest request = new GetDocumentStreamRequest();
request.setDocumentId("document-id");
request.setVersionId("version-id");
Uploading a document
Amazon WorkDocs Content Manager provides an API for uploading content to an Amazon WorkDocs site.
The following examples demonstrate how to upload a document using Java and C#.
Java
C#
20
Amazon WorkDocs Developer Guide
Uploading a document
};
workDocsContentManager.UploadDocumentStreamAsync(uploadDocumentStreamRequest).Wait();
21
Amazon WorkDocs Developer Guide
AWS glossary
For the latest AWS terminology, see the AWS glossary in the AWS General Reference.
22