0

as far as i know i can share or download a document in Workdocs via the Amazon Workdocs UI. I am trying to build a static website in a S3 bucket that offers a Link to a Workdoc document for download.

Thus i have to share this document after verifying some stuff. Sadly i found nothing similiar in the API documentation (https://docs.aws.amazon.com/workdocs/latest/APIReference/workdocs-api.pdf).

NodeJs would be fine using JDK but i can also try to use lambda functions if necessary.

Greetings,

Eric

w.eric
  • 321
  • 5
  • 15

1 Answers1

1

You can build AWS python3+ based AWS Lambda along with AWS Step Functions.

import boto3

work_docs_client = boto3.client('workdocs')  # Change aws connection parameters as per your setup


def lambda_handler(event, context):
    # Call share_document_work_docs(resource_id, recipient_id) based on your conditions/checks
    return None  # change this as per your use-case


# This will add the permissions to the document to share
def share_document_work_docs(resource_id, recipient_id):
    principals = [{'Id': recipient_id, 'Type': 'USER', 'Role': 'VIEWER'}]  # change this as per your use-case

    share_doc_response = work_docs_client.add_resource_permissions(

        ResourceId=resource_id,
        Principals=principals,
        NotificationOptions={
            'SendEmail': True,
            'EmailMessage': 'Your message here',
        }  # change NotificationOptions as per your use-case
    )

    return share_doc_response

amitd
  • 1,497
  • 4
  • 11
  • i kind of understand your answer i guess. i tried this with an AuthenticationToken and i get a 200 response. i dont quite understand two things though: - how can i read the share_doc_response? - if i understand this right, this will share the document with a specific user, but i want to share it with a person that is unauthenticated. – w.eric Jan 29 '21 at 08:18
  • @w-eric - 1) `share_doc_response` is of type Python Dictionary (a.k.a. `dict`). So you can refer [this add_resource_permissions](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/workdocs.html#WorkDocs.Client.add_resource_permissions) API response syntax. I would suggest to `print (share_doc_response)` just to view the api response structure in your example. Regarding how to read from `share_doc_response` `dict`, you can refer [this](https://www.w3schools.com/python/python_dictionaries.asp) python document about `dict`. – amitd Jan 29 '21 at 09:45
  • @w-eric - 2) Regarding, share it with a person that is unauthenticated. You can refer boto3 API document as well as [aws cli example inputs only](https://docs.aws.amazon.com/cli/latest/reference/workdocs/add-resource-permissions.html) provided for `anonymous` access. You can pass same inputs for this case. – amitd Jan 29 '21 at 09:46