Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Publish any AWS quicksight dashboards to public with lambda and API gateway
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