We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Custom fonts from S3 in AWS Lambda (.NET)

Hi everyone,

We’re implementing our custom .docx to .pdf converter using AWS lambda in .NET using Aspose.Words (21.5.0). We’ve created a bucket with the folder called Fonts and we’ve uploaded single Roboto font to that folder to test this converting logic.

As a truth of source, we’re using this documentation: https://docs.aspose.com/words/net/integration-in-aws-lambda/.

We’ve copied all the code from the documentation but instead of builder.Font.Name = "Noto Sans"; we’ve used builder.Font.Name = "Roboto";

After running this application locally we’ve got perfect results. But once we’ve deployed the application to AWS Lambda the fallback font was used and our custom one wasn’t loaded rendered.

After the debugging, we’ve found that .GetAvailableFonts().Count returns 1 locally, but 0 remotely and we think this is an issue.

Screenshot 2021-05-19 at 15.35.03.jpg (47.1 KB)

Could you please give us a piece of advice on how we can fix it and start using custom fonts from the S3 bucket in AWS Lambda!

Thanks in advance!

@vadym.shashkov Please make sure the following line of code returns the list of fonts in your S3 bucket.

response = await client.ListObjectsV2Async(request)

Make sure the bucket name and the key are properly specified in the request.

ListObjectsV2Request request = new ListObjectsV2Request()
{
     BucketName = bucketName,
     Prefix = fontsFolderKey
}

And finally, make sure you have permission to perform the s3:Listbucket.

Thank you for the response.

I’ve double-checked everything from your suggestion, and I’m sure that everything is correct from our side.

1 - Logs from Lambda execution, where we can see that we’ve got the font from the S3 ListObjectsV2Async():
Screenshot 2021-05-20 at 10.36.08.jpg (44.9 KB)
2 - Logs from local Lambda execution:
Screenshot 2021-05-20 at 10.39.57.png (74.7 KB)
3 - Our policy for this user:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "***",
            "Effect": "Allow",
            "Action": [
                "s3:*",
                "s3:Get*",
                "s3:List*",
                "s3:ListBucket"
            ],
            "Resource": "***"
        }
    ]
}

@vadym.shashkov If GetAvailableFonts returns zero, this means OpenFontDataStream method implementation returns either null or stream with invalid font.
In the code example:

public override Stream OpenFontDataStream()
{
    GetObjectRequest request = new GetObjectRequest
    {
        BucketName = mBucketName,
        Key = mKey
    };
                
    MemoryStream fontStream = new MemoryStream();
    Task<GetObjectResponse> task = Task.Run(async () => await mClient.GetObjectAsync(request));
    using (GetObjectResponse response = task.Result)
    {
        response.ResponseStream.CopyTo(fontStream);
        fontStream.Position = 0;
    }
    return fontStream;
}

This can occur if mClient.GetObjectAsync(request)) response does not contain valid font data. Could you please dump the data from the resulting fontStream and make sure it contains a valid font?

Alexey, thanks a lot for your help.

We’ve figured it out. The problem was with the policies we set for the user. We didn’t set /* in our Resource rule.

We had:
"Resource":["arn:aws:s3:::BUCKET"]

Instead of:
"Resource":["arn:aws:s3:::BUCKET/*"]

@vadym.shashkov It is perfect that you managed to figure the problem out. Please feel free to ask in case of any issues, we are always glad to assist you.

1 Like