Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jasonmccallister's avatar

AWS Lambda support for Telescope, Nova etc

I've deployed a lot of APIs to AWS Lambda with Laravel and have really enjoyed it. One of the things that makes it less enjoyable are using tools from the Laravel ecosystem like Telescope, Nova, Filament, etc. All of these tools require files (CSS, JS, etc) to be accessed from the same server as the API (e.g. the Lambda function) which by default does not work, you will end up with unusable pages.

Is there a better way to work around these? I find it strange that Laravel has a first party hosting with Lambda but these are (maybe?) not supported out of the box on its own platform?

Reference:

0 likes
1 reply
LaryAI's avatar
Level 58

Deploying Laravel applications to AWS Lambda using Bref can indeed present challenges when it comes to serving static assets required by tools like Telescope, Nova, and Filament. Here are some strategies to work around these issues:

1. Serve Static Assets from S3

One common approach is to serve static assets (CSS, JS, images, etc.) from an S3 bucket. This way, you can offload the serving of these assets to S3, which is highly scalable and cost-effective.

Steps:

  1. Upload Assets to S3:

    • Use a deployment script or a CI/CD pipeline to upload your static assets to an S3 bucket.
  2. Configure S3 Bucket:

    • Make sure your S3 bucket is publicly accessible or configure it to serve the assets via CloudFront for better performance and security.
  3. Update Asset URLs:

    • Update the URLs in your Laravel application to point to the S3 bucket. You can do this by setting the ASSET_URL environment variable in your .env file.
ASSET_URL=https://your-s3-bucket-name.s3.amazonaws.com
  1. Use the asset Helper:
    • Ensure you are using the asset helper function in your Blade templates to generate URLs for your assets.
<link rel="stylesheet" href="{{ asset('css/app.css') }}">
<script src="{{ asset('js/app.js') }}"></script>

2. Use CloudFront for Caching

To further optimize the delivery of your static assets, you can use AWS CloudFront as a CDN in front of your S3 bucket.

Steps:

  1. Create a CloudFront Distribution:

    • Create a CloudFront distribution and set your S3 bucket as the origin.
  2. Update Asset URLs:

    • Update the ASSET_URL in your .env file to point to the CloudFront distribution URL.
ASSET_URL=https://your-cloudfront-distribution-id.cloudfront.net

3. Configure Bref for Binary Responses

If you need to serve binary files (like images) directly from your Lambda function, you can configure Bref to handle binary responses.

Steps:

  1. Update serverless.yml:
    • Add the binaryMediaTypes configuration to your serverless.yml file.
provider:
  name: aws
  runtime: provided.al2
  environment:
    APP_STORAGE: /tmp
  apiGateway:
    binaryMediaTypes:
      - '*/*'
  1. Set Response Headers:
    • Ensure your Lambda function sets the correct Content-Type headers for binary responses.
return response($binaryContent)
    ->header('Content-Type', 'image/png')
    ->header('Content-Disposition', 'inline; filename="image.png"');

4. Use Custom Domains

If you are using custom domains, ensure that your API Gateway and CloudFront distributions are correctly configured to handle requests to your static assets.

Steps:

  1. Configure Custom Domain in API Gateway:

    • Set up a custom domain in API Gateway and map it to your Lambda function.
  2. Configure Custom Domain in CloudFront:

    • Set up a custom domain in CloudFront and map it to your S3 bucket.
  3. Update DNS Records:

    • Update your DNS records to point to the CloudFront distribution.

Conclusion

By serving static assets from S3 and using CloudFront for caching, you can significantly improve the performance and reliability of your Laravel applications deployed on AWS Lambda. Additionally, configuring Bref for binary responses ensures that your application can handle all types of content effectively.

If you follow these steps, you should be able to use Laravel tools like Telescope, Nova, and Filament without any issues on AWS Lambda.

Please or to participate in this conversation.