I built a python lambda which generates a zip file containing a certificate and password. The file is base64 encoded and returned using proxy integration through the API gateway. Hitting the API gateway with a the browser prompts to download. The response is saved to a file with a zip extension.
The saved file is still base64 encoded. The end users should receive a working zip file. Base64 decoding the file gives a valid zip file. The user should not have to decode the file.
Adding a Content-Encoding
header causes the API gateway integration to fail with the error that it cannot base64 decode the response from the lambda.
Note - Stripping the leading and trailing characters from the b64content fixes the str()
function putting a leading b'
and trailing tic. Can you tell I'm a noob to python and AWS? ;-)
headers = {'Content-Type': 'application/zip, application/octet-stream',
'Content-Disposition': f'attachment; filename="{filename}.zip"'
}
if 'b64' in event['params']:
headers['Content-Encoding'] = 'base64'
response = {
'statusCode': 200,
'isBase64Encoded': True,
'headers': headers,
'body': str(b64content)[2:-1],
}