Setting up permissions

As with all things AWS, we'll need to ensure IAM permissions are set up correctly. The UploadImage function will interact with a single AWS resource other than itself, and that is the ResizeImage function. For UploadImage to invoke ResizeImage, we need to grant it explicit permission.

Additionally, ResizeImage needs access to write data to the final resting place of the resized photos. We'll place these images in a different S3 bucket and again grant access via the iamRoleStatements section.

You can see both of these statements in the following code, along with other configurations in the full serverless.yml file:

service: fanoutprovider:  name: aws  runtime: nodejs4.3  region: ${env:AWS_REGION}  timeout: 30 iamRoleStatements: ...

Get Serverless Design Patterns and Best Practices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.