首页 > 解决方案 > 有没有办法通过 Workdocs API 在 Workdocs 中共享文档?

问题描述

据我所知,我可以通过 Amazon Workdocs UI 在 Workdocs 中共享或下载文档。我正在尝试在 S3 存储桶中构建一个静态网站,该网站提供指向 Workdoc 文档的链接以供下载。

因此,我必须在验证一些内容后分享此文档。遗憾的是,我在 API 文档( https://docs.aws.amazon.com/workdocs/latest/APIReference/workdocs-api.pdf)中没有发现任何类似的东西。

NodeJs 使用 JDK 会很好,但如果需要,我也可以尝试使用 lambda 函数。

问候,

埃里克

标签: amazon-web-servicesaws-lambdaamazon-workdocs

解决方案


您可以构建基于 AWS python3+ 的 AWS Lambda 以及 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


推荐阅读