🎥 Make videos programmatically with React
node JS apis documented
Jonny Burgerbc9f0b286658
diff --git a/packages/docs/docs/getorcreatebucket.md b/packages/docs/docs/getorcreatebucket.mdindex cb8aca3a84..8a2c3b9327 100644--- a/packages/docs/docs/getorcreatebucket.md+++ b/packages/docs/docs/getorcreatebucket.md@@ -3,3 +3,37 @@ id: getorcreatebuckettitle: getOrCreateBucket()slug: /lambda/getorcreatebucket---++Creates a bucket for Remotion Lambda in your S3 account. If one already exists, it will get returned instead.++**Only 1 bucket per region** is necessary for Remotion Lambda to function.++```ts twoslash+// @module: ESNext+// @target: ESNext+import {getOrCreateBucket} from '@remotion/lambda';++const {bucketName} = await getOrCreateBucket({region: 'us-east-1'})++console.log(bucketName) // "remtionlambda-32df3p"+```++## Arguments++An object with the following property:++### `region`++The [AWS region](/docs/lambda/region-selection) which you want to create a bucket in.++## Return value++A promise resolving to an object with the following property:++### `bucketName`++The name of your bucket that was found or created.++## See also++- [getFunctions()](/docs/lambda/getfunctions)diff --git a/packages/docs/docs/simulatepermissions.md b/packages/docs/docs/simulatepermissions.mdindex 7bad6d2bcb..d0c8559ab9 100644--- a/packages/docs/docs/simulatepermissions.md+++ b/packages/docs/docs/simulatepermissions.md@@ -3,3 +3,76 @@ id: simulatepermissionstitle: simulatePermissions()slug: /lambda/simulatepermissions---++Runs tests through the AWS Simulator ensuring that all the necessary permissions are set for the authenticated user.++Makes a lot of requests to AWS. Avoid calling the function many times in quick succession to hit a rate limit.++The CLI equivalent is `npx remotion lambda policies validate`.++The function does reject with an error if a permission is missing, rather the missing permission is indicated in the return value.++## Example++```ts twoslash+// @module: esnext+// @target: es2017++import {simulatePermissions} from '@remotion/lambda';++const {results} = await simulatePermissions({+ region: 'us-east-1',+});++for (const result of results) {+ console.log(result.decision) // "allowed"+ console.log(result.name) // "iam:GetUser"+}+```++## Arguments++An object with the following properties:++### `region`++The [AWS region](/docs/lambda/region-selection) that you would like to query.++### `onSimulation`++_optional_++A callback function that gets called every time a new simulation has been executed. This allows you to react to new simulation results coming in much faster than waiting for the return value of the function. Example:++```ts twoslash+// @module: esnext+// @target: es2017++import {simulatePermissions} from '@remotion/lambda';++const {results} = await simulatePermissions({+ region: 'us-east-1',+ onSimulation: (result) => {+ console.log(result.decision) // "allowed"+ console.log(result.name) // "iam:GetUser"+ }+});+```++## Return value++**An array of objects** containing simulation results of each necessary permission. The objects contain the following keys:++### `decision`++Either `"allowed"`, `"implicitDeny"` or `"explicitDeny"`.++### `name`++The identifier of the required permission. See the [Permissions page](/docs/lambda/permissions) to see a list of required permissions.++## See also++- [getUserPolicy()](/docs/lambda/getuserpolicy)+- [getRolePolicy()](/docs/lambda/getrolepolicy)+- [Permissions](/docs/lambda/permissions)diff --git a/packages/lambda/src/api/iam-validation/simulate.ts b/packages/lambda/src/api/iam-validation/simulate.tsindex c7a68f6d5e..d25428388b 100644--- a/packages/lambda/src/api/iam-validation/simulate.ts+++ b/packages/lambda/src/api/iam-validation/simulate.ts@@ -14,27 +14,36 @@ const getEmojiForStatus = (decision: EvalDecision) => {}};-const logPermissionOutput = (output: SimulationResult[]) => {- for (const result of output) {- Log.info([getEmojiForStatus(result.decision), result.name].join(' '));- }+export const logPermissionOutput = (output: SimulationResult) => {+ Log.info([getEmojiForStatus(output.decision), output.name].join(' '));};-export const simulatePermissions = async (options: {region: AwsRegion}) => {+export const simulatePermissions = async (options: {+ region: AwsRegion;+ onSimulation?: (result: SimulationResult) => void;+}): Promise<{+ results: SimulationResult[];+}> => {const user = await getIamClient(options.region).send(new GetUserCommand({}));if (!user || !user.User) {throw new Error('No valid AWS user detected');}+ const results: SimulationResult[] = [];+for (const per of requiredPermissions) {- logPermissionOutput(- await simulateRule({- actionNames: per.actions,- arn: user.User.Arn as string,- region: options.region,- resource: per.resource,- })- );+ const result = await simulateRule({+ actionNames: per.actions,+ arn: user.User.Arn as string,+ region: options.region,+ resource: per.resource,+ });+ for (const res of result) {+ results.push(res);+ options.onSimulation?.(res);+ }}++ return {results};};diff --git a/packages/lambda/src/cli/commands/policies/validate.ts b/packages/lambda/src/cli/commands/policies/validate.tsindex 7b7e0bcee6..fb0084f93b 100644--- a/packages/lambda/src/cli/commands/policies/validate.ts+++ b/packages/lambda/src/cli/commands/policies/validate.ts@@ -1,13 +1,20 @@-import {simulatePermissions} from '../../../api/iam-validation/simulate';+import {+ logPermissionOutput,+ simulatePermissions,+} from '../../../api/iam-validation/simulate';import {getAwsRegion} from '../../get-aws-region';import {Log} from '../../log';export const VALIDATE_SUBCOMMAND = 'validate';-export const validateSubcommand = async () => {try {- await simulatePermissions({region: getAwsRegion()});+ await simulatePermissions({+ region: getAwsRegion(),+ onSimulation: (res) => {+ Log.info(logPermissionOutput(res));+ },+ });} catch (err) {Log.error('Did not have the required permissions on AWS:');Log.error(err);