Example setup without IAM user
This is a write up of how to use the example for the technique described under "Using Lambda without IAM roles".
Prequisites
- Ensure that your local AWS profile is able to deploy to AWS.
Setup
1. Clone or download the project
The project can be found at reference project.
2. Install dependencies
- npm
- yarn
- pnpm
bash
bash
bash
3. Create the CDK Stack
This command will deploy the Lambda function and any other resources in the stack.
bash
The Remotion packages are also bundled into the stack, these ensures that renderMediaOnLambda() can be executed by the Lambda function.
package.jsonjson
The full dependencies are included in the reference project.
4. After deployment
bash
Deployment progressbash
Outputbash
The output contains the API Gateway base URL, region and Cognito client ID and user pool ID, which are used for authentication.
5. Cleanup
The following will delete the function, in case it's not needed anymore.
bash
Lambda role
The CDK creates an IAM role named remotionLambdaServerlessRole which needs the Remotion policy setup.
Test your endpoint
The API is secured by Cognito which requires an authorization token.
In order to test, you need to do the steps below, just in case you still don't have frontend.
1. Create a Cognito User
bash
2. Confirm the user so they can sign in
bash
3. Log the user to retrieve an identity JWT token
bash
YOUR_USER_POOL_CLIENT_ID and YOUR_USER_POOL_ID are part of the CDK output.
Outputbash
The API will give you a verbose response but will only use the IdToken.
4. Use the token to invoke a request to the endpoint using curl.
Request
bash
Response
bash
That's it! You now have an API that you can use to invoke the rendering of a video.
It is important to note that the Lambda function should not be accessible to unauthenticated users.
The function uses version 2 of the CDK, which is still being actively developed.
Next Steps
- Customize the Lambda function so that the rendered video will be moved to another directory.
- Try assigning the Remotion role via CDK code.
- Add request parameters to the Lambda function as input parameters for renderMediaOnLambda().
See also
- Using Lambda without IAM user
- Permissions
- Some code is borrowed from bobbyhadz.com