Search⌘ K

Modifying API Endpoints

Explore how to enhance your AWS Lambda serverless application by modifying API endpoints with path parameters. Learn to support multiple image formats securely by validating uploads and handling flexible request paths. This lesson equips you to build adaptable and maintainable serverless APIs.

This chapter explains how to structure SAM application templates and source code to make it easy to support, maintain, and evolve applications in the future. You will also learn about protecting serverless applications against abuse.

To avoid conflicts between user uploads, the ShowFormFunction function you created in Chapter 10 creates a random upload key and appends the .jpg image extension. In the previous chapter, you made user interactions much nicer, but you’re still restricting users from converting JPG images. ImageMagick can handle many image formats easily, so you can make the application a lot more useful by letting users upload PNG and GIF images as well.

To support multiple formats, you just need to ensure that users upload images to S3 with the correct extensions, so ImageMagick can load the files appropriately. Restricting uploads to .jpg was necessary for Chapter 10 because you had no client-facing logic. ShowFormFunction needs to limit the uploads to something, and the client couldn’t specify upfront what it wants. Now that the client code is smarter, it could ask for an upload policy for a specific image type.

API endpoints with path parameters

...