Skip to content

Instantly share code, notes, and snippets.

@vaquarkhan
Forked from umihico/lambda_function.py
Created March 5, 2022 01:35
Show Gist options
  • Select an option

  • Save vaquarkhan/a3d9e5d608c16411a27d19665a1e6fe7 to your computer and use it in GitHub Desktop.

Select an option

Save vaquarkhan/a3d9e5d608c16411a27d19665a1e6fe7 to your computer and use it in GitHub Desktop.
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