Created
December 12, 2019 07:46
-
-
Save umihico/7a45c5730f22eb3f58abce8455c68a39 to your computer and use it in GitHub Desktop.
Publish any AWS quicksight dashboards to public with lambda and API gateway
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import boto3 | |
""" | |
API gateway URL example. You have to allow your quicksight domin setting to be accessed from amazonaws.com including subdomains. | |
https://xxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/xxx-gateway-stage-xxxx/your-lambda-func-name?dashboard_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxx | |
""" | |
def lambda_handler(event, context): | |
dashboard_id=event["queryStringParameters"]['dashboard_id'] | |
client = boto3.client('quicksight', | |
aws_access_key_id= 'XXXXXXXXXXXXXXXXXX', | |
aws_secret_access_key= 'xxxXXXXXxxxxxXXXXXXXXXXXX') | |
response = client.get_dashboard_embed_url( | |
AwsAccountId='XXXXXXXX', # not root account example in this gist | |
DashboardId=dashboard_id, | |
SessionLifetimeInMinutes=600, | |
IdentityType='IAM', | |
UndoRedoDisabled=False, | |
ResetDisabled=False, | |
) | |
EmbedUrl=response['EmbedUrl'] | |
body = f'<html><body><iframe src="{EmbedUrl}" width="100%" height="100%" frameBorder="0"></iframe></body></html>' | |
content_type="text/html" | |
return { | |
'statusCode': 200, | |
'body': body, | |
"headers": { | |
'Content-Type': content_type, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment