@remotion/lambda 4.0.508 → 4.0.510

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/admin/make-layer-public.js +6 -5
  2. package/dist/api/create-function.d.ts +2 -1
  3. package/dist/api/create-function.js +57 -20
  4. package/dist/api/deploy-function.d.ts +7 -2
  5. package/dist/api/deploy-function.js +10 -1
  6. package/dist/api/get-regions.d.ts +1 -1
  7. package/dist/api/iam-validation/resolve-caller-arn.d.ts +6 -0
  8. package/dist/api/iam-validation/resolve-caller-arn.js +28 -0
  9. package/dist/api/iam-validation/role-permissions.d.ts +5 -2
  10. package/dist/api/iam-validation/role-permissions.js +9 -7
  11. package/dist/api/iam-validation/simulate.js +8 -22
  12. package/dist/api/iam-validation/suggested-policy.d.ts +6 -2
  13. package/dist/api/iam-validation/suggested-policy.js +28 -26
  14. package/dist/api/iam-validation/user-permissions.d.ts +5 -2
  15. package/dist/api/iam-validation/user-permissions.js +14 -10
  16. package/dist/cli/args.d.ts +1 -0
  17. package/dist/cli/commands/functions/deploy.js +7 -0
  18. package/dist/cli/commands/policies/role.js +5 -1
  19. package/dist/cli/commands/policies/user.js +5 -1
  20. package/dist/cli/commands/quotas/increase.js +4 -2
  21. package/dist/cli/commands/quotas/list.js +2 -1
  22. package/dist/cli/commands/render/render.js +2 -2
  23. package/dist/cli/commands/still.js +2 -2
  24. package/dist/cli/get-aws-region.d.ts +1 -1
  25. package/dist/cli/helpers/get-s3-output-provider-from-cli.d.ts +1 -1
  26. package/dist/esm/index.mjs +274 -147
  27. package/dist/esm/policies.mjs +36 -38
  28. package/dist/functions/helpers/get-current-region.d.ts +1 -1
  29. package/dist/functions/helpers/make-aws-artifact.d.ts +1 -1
  30. package/dist/functions/helpers/make-aws-artifact.js +3 -1
  31. package/dist/index.d.ts +3 -2
  32. package/dist/shared/get-layers.d.ts +1 -1
  33. package/dist/shared/get-layers.js +4 -2
  34. package/dist/shared/hosted-layers.d.ts +2 -1
  35. package/dist/shared/lambda-insights-extensions.js +2 -0
  36. package/dist/shared/validate-custom-layer-arns.d.ts +6 -0
  37. package/dist/shared/validate-custom-layer-arns.js +44 -0
  38. package/package.json +12 -12
  39. package/remotionlambda-arm64.zip +0 -0
@@ -74,7 +74,7 @@ const makeLayerPublic = async () => {
74
74
  const skipRegions = parseSkipFlag();
75
75
  const regions = onlyRegion
76
76
  ? [onlyRegion]
77
- : (0, get_regions_1.getRegions)().filter((r) => !skipRegions.includes(r));
77
+ : (0, get_regions_1.getRegions)().filter((r) => r in layerInfo && !skipRegions.includes(r));
78
78
  if (onlyRegion) {
79
79
  console.log(`Filtering to region: ${onlyRegion}`);
80
80
  }
@@ -82,6 +82,10 @@ const makeLayerPublic = async () => {
82
82
  console.log(`Skipping regions: ${skipRegions.join(', ')}`);
83
83
  }
84
84
  for (const region of regions) {
85
+ if (!(region in layerInfo)) {
86
+ throw new Error(`Remotion-hosted Layers are not supported in ${region}.`);
87
+ }
88
+ const hostedLayerRegion = region;
85
89
  for (const layer of layers) {
86
90
  const layerName = `remotion-binaries-${layer}-arm64`;
87
91
  const { Version, LayerArn } = await lambda_client_1.LambdaClientInternals.getLambdaClient(region, undefined, null).send(new client_lambda_1.PublishLayerVersionCommand({
@@ -109,16 +113,13 @@ const makeLayerPublic = async () => {
109
113
  VersionNumber: Version,
110
114
  StatementId: 'public-layer',
111
115
  }));
112
- if (!layerInfo[region]) {
113
- layerInfo[region] = [];
114
- }
115
116
  if (!LayerArn) {
116
117
  throw new Error('layerArn is null');
117
118
  }
118
119
  if (!Version) {
119
120
  throw new Error('Version is null');
120
121
  }
121
- layerInfo[region].push({
122
+ layerInfo[hostedLayerRegion].push({
122
123
  layerArn: LayerArn,
123
124
  version: Version,
124
125
  });
@@ -13,6 +13,7 @@ type CreateFunctionInput = {
13
13
  retentionInDays: number;
14
14
  ephemerealStorageInMb: number;
15
15
  customRoleArn: string;
16
+ customLayerArns: string[] | null;
16
17
  enableLambdaInsights: boolean;
17
18
  logLevel: LogLevel;
18
19
  vpcSubnetIds: string;
@@ -20,7 +21,7 @@ type CreateFunctionInput = {
20
21
  runtimePreference: RuntimePreference;
21
22
  requestHandler: RequestHandler | null;
22
23
  };
23
- export declare const createFunction: ({ createCloudWatchLogGroup, region, zipFile, functionName, accountId, memorySizeInMb, timeoutInSeconds, alreadyCreated, retentionInDays, ephemerealStorageInMb, customRoleArn, enableLambdaInsights, logLevel, vpcSubnetIds, vpcSecurityGroupIds, runtimePreference, requestHandler, }: CreateFunctionInput) => Promise<{
24
+ export declare const createFunction: ({ createCloudWatchLogGroup, region, zipFile, functionName, accountId, memorySizeInMb, timeoutInSeconds, alreadyCreated, retentionInDays, ephemerealStorageInMb, customRoleArn, customLayerArns, enableLambdaInsights, logLevel, vpcSubnetIds, vpcSecurityGroupIds, runtimePreference, requestHandler, }: CreateFunctionInput) => Promise<{
24
25
  FunctionName: string;
25
26
  }>;
26
27
  export {};
@@ -11,8 +11,9 @@ const version_1 = require("remotion/version");
11
11
  const get_layers_1 = require("../shared/get-layers");
12
12
  const lambda_insights_extensions_1 = require("../shared/lambda-insights-extensions");
13
13
  const suggested_policy_1 = require("./iam-validation/suggested-policy");
14
- const createFunction = async ({ createCloudWatchLogGroup, region, zipFile, functionName, accountId, memorySizeInMb, timeoutInSeconds, alreadyCreated, retentionInDays, ephemerealStorageInMb, customRoleArn, enableLambdaInsights, logLevel, vpcSubnetIds, vpcSecurityGroupIds, runtimePreference, requestHandler, }) => {
15
- var _a;
14
+ const createFunction = async ({ createCloudWatchLogGroup, region, zipFile, functionName, accountId, memorySizeInMb, timeoutInSeconds, alreadyCreated, retentionInDays, ephemerealStorageInMb, customRoleArn, customLayerArns, enableLambdaInsights, logLevel, vpcSubnetIds, vpcSecurityGroupIds, runtimePreference, requestHandler, }) => {
15
+ var _a, _b, _c;
16
+ var _d, _e, _f, _g;
16
17
  if (createCloudWatchLogGroup) {
17
18
  renderer_1.RenderInternals.Log.verbose({ indent: false, logLevel }, 'Creating CloudWatch group');
18
19
  try {
@@ -37,15 +38,52 @@ const createFunction = async ({ createCloudWatchLogGroup, region, zipFile, funct
37
38
  }));
38
39
  renderer_1.RenderInternals.Log.verbose({ indent: false, logLevel }, `Set retention to ${retentionInDays} days`);
39
40
  }
41
+ const insightsLayer = enableLambdaInsights
42
+ ? lambda_insights_extensions_1.lambdaInsightsExtensions[region]
43
+ : null;
44
+ if (enableLambdaInsights && !insightsLayer) {
45
+ throw new Error(`Lambda Insights is not supported by AWS in region ${region}. Please disable Lambda Insights. See http://remotion.dev/docs/lambda/insights#unsupported-regions`);
46
+ }
47
+ const layers = (customLayerArns !== null && customLayerArns !== void 0 ? customLayerArns : (0, get_layers_1.getLayers)({
48
+ option: runtimePreference,
49
+ region,
50
+ }).map(({ layerArn, version }) => `${layerArn}:${version}`)).concat(insightsLayer ? [insightsLayer] : []);
40
51
  if (alreadyCreated) {
41
52
  renderer_1.RenderInternals.Log.verbose({ indent: false, logLevel }, `Function ${functionName} already existed`);
53
+ if (customLayerArns === null) {
54
+ return { FunctionName: functionName };
55
+ }
56
+ const lambdaClient = lambda_client_1.LambdaClientInternals.getLambdaClient(region, undefined, requestHandler);
57
+ const currentConfiguration = await lambdaClient.send(new client_lambda_1.GetFunctionConfigurationCommand({ FunctionName: functionName }));
58
+ const currentLayers = ((_d = currentConfiguration.Layers) !== null && _d !== void 0 ? _d : []).map((layer) => layer.Arn);
59
+ const layersAreEqual = currentLayers.length === layers.length &&
60
+ currentLayers.every((layer, index) => layer === layers[index]);
61
+ if (layersAreEqual) {
62
+ return { FunctionName: functionName };
63
+ }
64
+ renderer_1.RenderInternals.Log.verbose({ indent: false, logLevel }, `Updating Layers for function ${functionName}`);
65
+ await lambdaClient.send(new client_lambda_1.UpdateFunctionConfigurationCommand({
66
+ FunctionName: functionName,
67
+ Layers: layers,
68
+ }));
69
+ while (true) {
70
+ const configuration = await lambdaClient.send(new client_lambda_1.GetFunctionConfigurationCommand({ FunctionName: functionName }));
71
+ if (configuration.State === 'Failed' ||
72
+ configuration.LastUpdateStatus === 'Failed') {
73
+ throw new Error(`Failed to update Layers for function ${functionName}: ${(_f = (_e = configuration.StateReason) !== null && _e !== void 0 ? _e : configuration.LastUpdateStatusReason) !== null && _f !== void 0 ? _f : 'Unknown reason'}`);
74
+ }
75
+ if (configuration.State === 'Active' &&
76
+ configuration.LastUpdateStatus !== 'InProgress') {
77
+ break;
78
+ }
79
+ await new Promise((resolve) => {
80
+ setTimeout(resolve, 1000);
81
+ });
82
+ }
42
83
  return { FunctionName: functionName };
43
84
  }
44
- const defaultRoleName = `arn:aws:iam::${accountId}:role/${suggested_policy_1.ROLE_NAME}`;
45
- const layers = (0, get_layers_1.getLayers)({
46
- option: runtimePreference,
47
- region,
48
- });
85
+ const { partition } = lambda_client_1.LambdaClientInternals.getAwsRegionMetadata(region);
86
+ const defaultRoleName = `arn:${partition}:iam::${accountId}:role/${suggested_policy_1.ROLE_NAME}`;
49
87
  let vpcConfig;
50
88
  if (vpcSubnetIds && vpcSecurityGroupIds) {
51
89
  vpcConfig = {
@@ -54,12 +92,6 @@ const createFunction = async ({ createCloudWatchLogGroup, region, zipFile, funct
54
92
  };
55
93
  }
56
94
  renderer_1.RenderInternals.Log.verbose({ indent: false, logLevel }, 'Deploying new Lambda function');
57
- const insightsLayer = enableLambdaInsights
58
- ? lambda_insights_extensions_1.lambdaInsightsExtensions[region]
59
- : null;
60
- if (enableLambdaInsights && !insightsLayer) {
61
- throw new Error(`Lambda Insights is not supported by AWS in region ${region}. Please disable Lambda Insights. See http://remotion.dev/docs/lambda/insights#unsupported-regions`);
62
- }
63
95
  const { FunctionName, FunctionArn } = await lambda_client_1.LambdaClientInternals.getLambdaClient(region, undefined, requestHandler).send(new client_lambda_1.CreateFunctionCommand({
64
96
  Code: {
65
97
  ZipFile: new Uint8Array((0, node_fs_1.readFileSync)(zipFile)),
@@ -71,9 +103,7 @@ const createFunction = async ({ createCloudWatchLogGroup, region, zipFile, funct
71
103
  Description: 'Renders a Remotion video.',
72
104
  MemorySize: memorySizeInMb,
73
105
  Timeout: timeoutInSeconds,
74
- Layers: layers
75
- .map(({ layerArn, version }) => `${layerArn}:${version}`)
76
- .concat(insightsLayer ? [insightsLayer] : []),
106
+ Layers: layers,
77
107
  Architectures: ['arm64'],
78
108
  EphemeralStorage: {
79
109
  Size: ephemerealStorageInMb,
@@ -110,6 +140,7 @@ const createFunction = async ({ createCloudWatchLogGroup, region, zipFile, funct
110
140
  renderer_1.RenderInternals.Log.verbose({ indent: false, logLevel }, 'Set function retries to 0.');
111
141
  renderer_1.RenderInternals.Log.verbose({ indent: false, logLevel }, 'Waiting for the function to be ready...');
112
142
  let state = 'Pending';
143
+ let currentRuntimeVersionArn = null;
113
144
  while (state === 'Pending') {
114
145
  const getFn = await lambda_client_1.LambdaClientInternals.getLambdaClient(region, undefined, requestHandler).send(new client_lambda_1.GetFunctionCommand({
115
146
  FunctionName,
@@ -118,21 +149,27 @@ const createFunction = async ({ createCloudWatchLogGroup, region, zipFile, funct
118
149
  setTimeout(() => resolve(), 1000);
119
150
  });
120
151
  state = (_a = getFn.Configuration) === null || _a === void 0 ? void 0 : _a.State;
152
+ currentRuntimeVersionArn = (_g = (_c = (_b = getFn.Configuration) === null || _b === void 0 ? void 0 : _b.RuntimeVersionConfig) === null || _c === void 0 ? void 0 : _c.RuntimeVersionArn) !== null && _g !== void 0 ? _g : null;
121
153
  }
122
154
  renderer_1.RenderInternals.Log.verbose({ indent: false, logLevel }, 'Function is now ready.');
123
155
  renderer_1.RenderInternals.Log.verbose({ indent: false, logLevel }, 'Locking the runtime version of the function...');
124
- const RuntimeVersionArn = `arn:aws:lambda:${region}::runtime:58a37e8413ed69058c4ac3b1df642118591f17d40def93d6101f867c72cd03c2`;
156
+ const runtimeVersionArn = partition === 'aws-cn'
157
+ ? currentRuntimeVersionArn
158
+ : `arn:aws:lambda:${region}::runtime:58a37e8413ed69058c4ac3b1df642118591f17d40def93d6101f867c72cd03c2`;
125
159
  try {
160
+ if (!runtimeVersionArn) {
161
+ throw new Error('AWS did not return a runtime version ARN.');
162
+ }
126
163
  await lambda_client_1.LambdaClientInternals.getLambdaClient(region, undefined, requestHandler).send(new client_lambda_1.PutRuntimeManagementConfigCommand({
127
164
  FunctionName,
128
165
  UpdateRuntimeOn: 'Manual',
129
- RuntimeVersionArn,
166
+ RuntimeVersionArn: runtimeVersionArn,
130
167
  }));
168
+ renderer_1.RenderInternals.Log.verbose({ indent: false, logLevel }, `Function runtime is locked to ${runtimeVersionArn}`);
131
169
  }
132
- catch (_b) {
170
+ catch (_h) {
133
171
  console.warn('⚠️ Could not lock the runtime version. We recommend to update your policies to prevent your functions from breaking in the future in case the AWS runtime changes. See https://remotion.dev/docs/lambda/feb-2023-incident for an example on how to update your policy.');
134
172
  }
135
- renderer_1.RenderInternals.Log.verbose({ indent: false, logLevel }, `Function runtime is locked to ${RuntimeVersionArn}`);
136
173
  return { FunctionName: FunctionName };
137
174
  };
138
175
  exports.createFunction = createFunction;
@@ -20,16 +20,21 @@ type OptionalParameters = {
20
20
  runtimePreference: RuntimePreference;
21
21
  requestHandler: RequestHandler | null;
22
22
  };
23
- export type DeployFunctionInput = MandatoryParameters & Partial<OptionalParameters>;
23
+ export type DeployFunctionInput = MandatoryParameters & Partial<OptionalParameters> & {
24
+ customLayerArns?: string[];
25
+ };
24
26
  export type DeployFunctionOutput = {
25
27
  functionName: string;
26
28
  alreadyExisted: boolean;
27
29
  };
28
30
  export declare const internalDeployFunction: <Provider extends CloudProvider<string, Record<string, unknown>, Record<string, unknown>, string, object>>(params: MandatoryParameters & OptionalParameters & {
31
+ customLayerArns: string[] | null;
29
32
  providerSpecifics: ProviderSpecifics<Provider>;
30
33
  fullClientSpecifics: FullClientSpecifics<Provider>;
31
34
  }) => Promise<DeployFunctionOutput>;
32
- export declare const deployFunction: ({ createCloudWatchLogGroup, memorySizeInMb, region, timeoutInSeconds, cloudWatchLogRetentionPeriodInDays, customRoleArn, enableLambdaInsights, indent, logLevel, enableV5Runtime, vpcSubnetIds, vpcSecurityGroupIds, runtimePreference, diskSizeInMb, requestHandler, }: MandatoryParameters & Partial<OptionalParameters> & {
35
+ export declare const deployFunction: ({ createCloudWatchLogGroup, memorySizeInMb, region, timeoutInSeconds, cloudWatchLogRetentionPeriodInDays, customRoleArn, customLayerArns, enableLambdaInsights, indent, logLevel, enableV5Runtime, vpcSubnetIds, vpcSecurityGroupIds, runtimePreference, diskSizeInMb, requestHandler, }: MandatoryParameters & Partial<OptionalParameters> & {
36
+ customLayerArns?: string[] | undefined;
37
+ } & {
33
38
  enableV5Runtime?: boolean | undefined;
34
39
  }) => Promise<DeployFunctionOutput>;
35
40
  export {};
@@ -8,6 +8,7 @@ const version_1 = require("remotion/version");
8
8
  const full_client_implementation_1 = require("../functions/full-client-implementation");
9
9
  const function_zip_path_1 = require("../shared/function-zip-path");
10
10
  const get_layers_1 = require("../shared/get-layers");
11
+ const validate_custom_layer_arns_1 = require("../shared/validate-custom-layer-arns");
11
12
  const validate_custom_role_arn_1 = require("../shared/validate-custom-role-arn");
12
13
  const validate_retention_period_1 = require("../shared/validate-retention-period");
13
14
  const validate_timeout_1 = require("../shared/validate-timeout");
@@ -20,6 +21,12 @@ const internalDeployFunction = async (params) => {
20
21
  lambda_client_1.LambdaClientInternals.validateDiskSizeInMb(params.diskSizeInMb);
21
22
  (0, validate_custom_role_arn_1.validateCustomRoleArn)(params.customRoleArn);
22
23
  (0, get_layers_1.validateRuntimePreference)(params.runtimePreference);
24
+ (0, validate_custom_layer_arns_1.validateCustomLayerArns)({
25
+ customLayerArns: params.customLayerArns,
26
+ enableLambdaInsights: params.enableLambdaInsights,
27
+ region: params.region,
28
+ runtimePreference: params.runtimePreference,
29
+ });
23
30
  const functionName = (0, lambda_client_1.speculateFunctionName)({
24
31
  diskSizeInMb: params.diskSizeInMb,
25
32
  memorySizeInMb: params.memorySizeInMb,
@@ -48,6 +55,7 @@ const internalDeployFunction = async (params) => {
48
55
  alreadyCreated: Boolean(alreadyDeployed),
49
56
  ephemerealStorageInMb: params.diskSizeInMb,
50
57
  customRoleArn: params.customRoleArn,
58
+ customLayerArns: params.customLayerArns,
51
59
  enableLambdaInsights: (_b = params.enableLambdaInsights) !== null && _b !== void 0 ? _b : false,
52
60
  logLevel: params.logLevel,
53
61
  vpcSubnetIds: params.vpcSubnetIds,
@@ -69,7 +77,7 @@ const errorHandled = (0, error_handling_1.wrapWithErrorHandling)(exports.interna
69
77
  * @description Creates an AWS Lambda function in your account that will be able to render a video in the cloud.
70
78
  * @see [Documentation](https://remotion.dev/docs/lambda/deployfunction)
71
79
  */
72
- const deployFunction = ({ createCloudWatchLogGroup, memorySizeInMb, region, timeoutInSeconds, cloudWatchLogRetentionPeriodInDays, customRoleArn, enableLambdaInsights, indent, logLevel, enableV5Runtime, vpcSubnetIds, vpcSecurityGroupIds, runtimePreference, diskSizeInMb, requestHandler, }) => {
80
+ const deployFunction = ({ createCloudWatchLogGroup, memorySizeInMb, region, timeoutInSeconds, cloudWatchLogRetentionPeriodInDays, customRoleArn, customLayerArns, enableLambdaInsights, indent, logLevel, enableV5Runtime, vpcSubnetIds, vpcSecurityGroupIds, runtimePreference, diskSizeInMb, requestHandler, }) => {
73
81
  if (enableV5Runtime) {
74
82
  console.warn('The `enableV5Runtime` option is now on by default. No need to specify it anymore.');
75
83
  }
@@ -78,6 +86,7 @@ const deployFunction = ({ createCloudWatchLogGroup, memorySizeInMb, region, time
78
86
  logLevel: logLevel !== null && logLevel !== void 0 ? logLevel : 'info',
79
87
  createCloudWatchLogGroup,
80
88
  customRoleArn: customRoleArn !== null && customRoleArn !== void 0 ? customRoleArn : undefined,
89
+ customLayerArns: customLayerArns !== null && customLayerArns !== void 0 ? customLayerArns : null,
81
90
  diskSizeInMb: diskSizeInMb !== null && diskSizeInMb !== void 0 ? diskSizeInMb : constants_1.DEFAULT_EPHEMERAL_STORAGE_IN_MB,
82
91
  enableLambdaInsights: enableLambdaInsights !== null && enableLambdaInsights !== void 0 ? enableLambdaInsights : false,
83
92
  memorySizeInMb,
@@ -1,5 +1,5 @@
1
1
  type Options = {
2
2
  enabledByDefaultOnly?: boolean;
3
3
  };
4
- export declare const getRegions: (options?: Options | undefined) => readonly ("af-south-1" | "ap-east-1" | "ap-northeast-1" | "ap-northeast-2" | "ap-northeast-3" | "ap-south-1" | "ap-southeast-1" | "ap-southeast-2" | "ap-southeast-4" | "ap-southeast-5" | "ca-central-1" | "eu-central-1" | "eu-central-2" | "eu-north-1" | "eu-south-1" | "eu-west-1" | "eu-west-2" | "eu-west-3" | "sa-east-1" | "us-east-1" | "us-east-2" | "us-west-1" | "us-west-2")[];
4
+ export declare const getRegions: (options?: Options | undefined) => readonly ("af-south-1" | "ap-east-1" | "ap-northeast-1" | "ap-northeast-2" | "ap-northeast-3" | "ap-south-1" | "ap-southeast-1" | "ap-southeast-2" | "ap-southeast-4" | "ap-southeast-5" | "ca-central-1" | "cn-north-1" | "cn-northwest-1" | "eu-central-1" | "eu-central-2" | "eu-north-1" | "eu-south-1" | "eu-west-1" | "eu-west-2" | "eu-west-3" | "sa-east-1" | "us-east-1" | "us-east-2" | "us-west-1" | "us-west-2")[];
5
5
  export {};
@@ -0,0 +1,6 @@
1
+ import type { AwsPartition } from '@remotion/lambda-client';
2
+ export declare const resolveCallerArnForSimulation: ({ callerIdentityArn, region, regionPartition, }: {
3
+ callerIdentityArn: string;
4
+ region: "af-south-1" | "ap-east-1" | "ap-northeast-1" | "ap-northeast-2" | "ap-northeast-3" | "ap-south-1" | "ap-southeast-1" | "ap-southeast-2" | "ap-southeast-4" | "ap-southeast-5" | "ca-central-1" | "cn-north-1" | "cn-northwest-1" | "eu-central-1" | "eu-central-2" | "eu-north-1" | "eu-south-1" | "eu-west-1" | "eu-west-2" | "eu-west-3" | "sa-east-1" | "us-east-1" | "us-east-2" | "us-west-1" | "us-west-2";
5
+ regionPartition: AwsPartition;
6
+ }) => string;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveCallerArnForSimulation = void 0;
4
+ const resolveCallerArnForSimulation = ({ callerIdentityArn, region, regionPartition, }) => {
5
+ const components = callerIdentityArn.match(/^arn:([^:]+):([^:]+)::(\d+):([^/]+)(.*)$/);
6
+ if (!components) {
7
+ throw new Error('Unknown AWS Caller Identity ARN detected');
8
+ }
9
+ const callerPartition = components[1];
10
+ if (callerPartition !== regionPartition) {
11
+ throw new Error(`AWS Caller Identity partition ${callerPartition} does not match region ${region}, which uses partition ${regionPartition}.`);
12
+ }
13
+ const service = components[2];
14
+ const accountId = components[3];
15
+ const resourceType = components[4];
16
+ if (service === 'iam' && resourceType === 'user') {
17
+ return callerIdentityArn;
18
+ }
19
+ if (service === 'sts' && resourceType === 'assumed-role') {
20
+ const assumedRoleComponents = components[5].match(/^\/([^/]+)\/(.*)$/);
21
+ if (!assumedRoleComponents) {
22
+ throw new Error('Unsupported AWS Caller Identity as Assumed-Role ARN detected');
23
+ }
24
+ return `arn:${callerPartition}:iam::${accountId}:role/${assumedRoleComponents[1]}`;
25
+ }
26
+ throw new Error('Unsupported AWS Caller Identity ARN detected');
27
+ };
28
+ exports.resolveCallerArnForSimulation = resolveCallerArnForSimulation;
@@ -1,4 +1,7 @@
1
- export declare const rolePermissions: {
1
+ import type { AwsPartition } from '@remotion/lambda-client';
2
+ export type RolePermission = {
2
3
  actions: string[];
3
4
  resource: string[];
4
- }[];
5
+ };
6
+ export declare const getRolePermissions: (partition: AwsPartition) => RolePermission[];
7
+ export declare const rolePermissions: RolePermission[];
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rolePermissions = void 0;
3
+ exports.rolePermissions = exports.getRolePermissions = void 0;
4
4
  const constants_1 = require("@remotion/lambda-client/constants");
5
- exports.rolePermissions = [
5
+ const getRolePermissions = (partition) => [
6
6
  {
7
7
  actions: ['s3:ListAllMyBuckets'],
8
8
  resource: ['*'],
@@ -18,21 +18,23 @@ exports.rolePermissions = [
18
18
  's3:PutObject',
19
19
  's3:GetBucketLocation',
20
20
  ],
21
- resource: [`arn:aws:s3:::${constants_1.REMOTION_BUCKET_PREFIX}*`],
21
+ resource: [`arn:${partition}:s3:::${constants_1.REMOTION_BUCKET_PREFIX}*`],
22
22
  },
23
23
  {
24
24
  actions: ['lambda:InvokeFunction'],
25
- resource: [`arn:aws:lambda:*:*:function:${constants_1.RENDER_FN_PREFIX}*`],
25
+ resource: [`arn:${partition}:lambda:*:*:function:${constants_1.RENDER_FN_PREFIX}*`],
26
26
  },
27
27
  {
28
28
  actions: ['logs:CreateLogGroup'],
29
- resource: [`arn:aws:logs:*:*:log-group:${constants_1.LAMBDA_INSIGHTS_PREFIX}`],
29
+ resource: [`arn:${partition}:logs:*:*:log-group:${constants_1.LAMBDA_INSIGHTS_PREFIX}`],
30
30
  },
31
31
  {
32
32
  actions: ['logs:CreateLogStream', 'logs:PutLogEvents'],
33
33
  resource: [
34
- `arn:aws:logs:*:*:log-group:${constants_1.LOG_GROUP_PREFIX}${constants_1.RENDER_FN_PREFIX}*`,
35
- `arn:aws:logs:*:*:log-group:${constants_1.LAMBDA_INSIGHTS_PREFIX}:*`,
34
+ `arn:${partition}:logs:*:*:log-group:${constants_1.LOG_GROUP_PREFIX}${constants_1.RENDER_FN_PREFIX}*`,
35
+ `arn:${partition}:logs:*:*:log-group:${constants_1.LAMBDA_INSIGHTS_PREFIX}:*`,
36
36
  ],
37
37
  },
38
38
  ];
39
+ exports.getRolePermissions = getRolePermissions;
40
+ exports.rolePermissions = (0, exports.getRolePermissions)('aws');
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.simulatePermissions = exports.logPermissionOutput = void 0;
4
4
  const client_sts_1 = require("@aws-sdk/client-sts");
5
5
  const lambda_client_1 = require("@remotion/lambda-client");
6
+ const resolve_caller_arn_1 = require("./resolve-caller-arn");
6
7
  const simulate_rule_1 = require("./simulate-rule");
7
8
  const user_permissions_1 = require("./user-permissions");
8
9
  const getEmojiForStatus = (decision) => {
@@ -27,29 +28,14 @@ const simulatePermissions = async (options) => {
27
28
  if (!(callerIdentity === null || callerIdentity === void 0 ? void 0 : callerIdentity.Arn)) {
28
29
  throw new Error('No valid AWS Caller Identity detected');
29
30
  }
30
- const callerIdentityArnComponents = callerIdentity.Arn.match(/arn:aws:([^:]+)::(\d+):([^/]+)(.*)/);
31
- if (!callerIdentityArnComponents) {
32
- throw new Error('Unknown AWS Caller Identity ARN detected');
33
- }
34
- const callerIdentityArnType = callerIdentityArnComponents[1];
35
- let callerArn;
36
- if (callerIdentityArnType === 'iam' &&
37
- callerIdentityArnComponents[3] === 'user') {
38
- callerArn = callerIdentity.Arn;
39
- }
40
- else if (callerIdentityArnType === 'sts' &&
41
- callerIdentityArnComponents[3] === 'assumed-role') {
42
- const assumedRoleComponents = callerIdentityArnComponents[4].match(/\/([^/]+)\/(.*)/);
43
- if (!assumedRoleComponents) {
44
- throw new Error('Unsupported AWS Caller Identity as Assumed-Role ARN detected');
45
- }
46
- callerArn = `arn:aws:iam::${callerIdentityArnComponents[2]}:role/${assumedRoleComponents[1]}`;
47
- }
48
- else {
49
- throw new Error('Unsupported AWS Caller Identity ARN detected');
50
- }
31
+ const { partition: regionPartition } = lambda_client_1.LambdaClientInternals.getAwsRegionMetadata(options.region);
32
+ const callerArn = (0, resolve_caller_arn_1.resolveCallerArnForSimulation)({
33
+ callerIdentityArn: callerIdentity.Arn,
34
+ region: options.region,
35
+ regionPartition,
36
+ });
51
37
  const results = [];
52
- for (const per of user_permissions_1.requiredPermissions) {
38
+ for (const per of (0, user_permissions_1.getRequiredPermissions)(regionPartition)) {
53
39
  const result = await (0, simulate_rule_1.simulateRule)({
54
40
  actionNames: per.actions,
55
41
  arn: callerArn,
@@ -1,3 +1,7 @@
1
- export declare const getUserPolicy: () => string;
1
+ import type { AwsPartition } from '@remotion/lambda-client';
2
+ export type GetPolicyOptions = {
3
+ partition?: AwsPartition;
4
+ };
5
+ export declare const getUserPolicy: (options?: GetPolicyOptions | undefined) => string;
2
6
  export declare const ROLE_NAME = "remotion-lambda-role";
3
- export declare const getRolePolicy: () => string;
7
+ export declare const getRolePolicy: (options?: GetPolicyOptions | undefined) => string;
@@ -3,42 +3,44 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getRolePolicy = exports.ROLE_NAME = exports.getUserPolicy = void 0;
4
4
  const role_permissions_1 = require("./role-permissions");
5
5
  const user_permissions_1 = require("./user-permissions");
6
- const suggestedPolicy = {
6
+ const makePolicy = (partition) => ({
7
7
  Version: '2012-10-17',
8
- Statement: [
9
- ...user_permissions_1.requiredPermissions.map((per) => {
10
- return {
11
- Sid: per.id,
12
- Effect: 'Allow',
13
- Action: per.actions,
14
- Resource: per.resource,
15
- };
16
- }),
17
- ],
18
- };
19
- const suggestedRolePolicy = {
8
+ Statement: (0, user_permissions_1.getRequiredPermissions)(partition).map((per) => {
9
+ return {
10
+ Sid: per.id,
11
+ Effect: 'Allow',
12
+ Action: per.actions,
13
+ Resource: per.resource,
14
+ };
15
+ }),
16
+ });
17
+ const makeRolePolicy = (partition) => ({
20
18
  Version: '2012-10-17',
21
- Statement: [
22
- ...role_permissions_1.rolePermissions.map((per, i) => {
23
- return {
24
- Sid: String(i),
25
- Effect: 'Allow',
26
- Action: per.actions,
27
- Resource: per.resource,
28
- };
29
- }),
30
- ],
31
- };
19
+ Statement: (0, role_permissions_1.getRolePermissions)(partition).map((per, i) => {
20
+ return {
21
+ Sid: String(i),
22
+ Effect: 'Allow',
23
+ Action: per.actions,
24
+ Resource: per.resource,
25
+ };
26
+ }),
27
+ });
32
28
  /*
33
29
  * @description Returns an inline JSON policy to be assigned to the AWS user whose credentials are being used for executing CLI commands or calling Node.JS functions.
34
30
  * @see [Documentation](https://remotion.dev/docs/lambda/getuserpolicy)
35
31
  */
36
- const getUserPolicy = () => JSON.stringify(suggestedPolicy, null, 2);
32
+ const getUserPolicy = (options) => {
33
+ var _a;
34
+ return JSON.stringify(makePolicy((_a = options === null || options === void 0 ? void 0 : options.partition) !== null && _a !== void 0 ? _a : 'aws'), null, 2);
35
+ };
37
36
  exports.getUserPolicy = getUserPolicy;
38
37
  exports.ROLE_NAME = 'remotion-lambda-role';
39
38
  /*
40
39
  * @description Returns an inline JSON policy to be assigned to the 'remotion-lambda-role' role that needs to be created in your AWS account.
41
40
  * @see [Documentation](https://remotion.dev/docs/lambda/getrolepolicy)
42
41
  */
43
- const getRolePolicy = () => JSON.stringify(suggestedRolePolicy, null, 2);
42
+ const getRolePolicy = (options) => {
43
+ var _a;
44
+ return JSON.stringify(makeRolePolicy((_a = options === null || options === void 0 ? void 0 : options.partition) !== null && _a !== void 0 ? _a : 'aws'), null, 2);
45
+ };
44
46
  exports.getRolePolicy = getRolePolicy;
@@ -1,5 +1,8 @@
1
- export declare const requiredPermissions: {
1
+ import type { AwsPartition } from '@remotion/lambda-client';
2
+ export type RequiredPermission = {
2
3
  actions: string[];
3
4
  resource: string[];
4
5
  id: string;
5
- }[];
6
+ };
7
+ export declare const getRequiredPermissions: (partition: AwsPartition) => RequiredPermission[];
8
+ export declare const requiredPermissions: RequiredPermission[];
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.requiredPermissions = void 0;
3
+ exports.requiredPermissions = exports.getRequiredPermissions = void 0;
4
4
  const constants_1 = require("@remotion/lambda-client/constants");
5
5
  const hosted_layers_1 = require("../../shared/hosted-layers");
6
- exports.requiredPermissions = [
6
+ const getRequiredPermissions = (partition) => [
7
7
  {
8
8
  id: 'HandleQuotas',
9
9
  actions: [
@@ -22,7 +22,7 @@ exports.requiredPermissions = [
22
22
  {
23
23
  id: 'LambdaInvokation',
24
24
  actions: ['iam:PassRole'],
25
- resource: ['arn:aws:iam::*:role/remotion-lambda-role'],
25
+ resource: [`arn:${partition}:iam::*:role/remotion-lambda-role`],
26
26
  },
27
27
  {
28
28
  id: 'Storage',
@@ -41,7 +41,7 @@ exports.requiredPermissions = [
41
41
  's3:PutBucketPolicy',
42
42
  's3:PutLifecycleConfiguration',
43
43
  ],
44
- resource: [`arn:aws:s3:::${constants_1.REMOTION_BUCKET_PREFIX}*`],
44
+ resource: [`arn:${partition}:s3:::${constants_1.REMOTION_BUCKET_PREFIX}*`],
45
45
  },
46
46
  {
47
47
  id: 'BucketListing',
@@ -64,21 +64,25 @@ exports.requiredPermissions = [
64
64
  'lambda:PutRuntimeManagementConfig',
65
65
  'lambda:TagResource',
66
66
  ],
67
- resource: [`arn:aws:lambda:*:*:function:${constants_1.RENDER_FN_PREFIX}*`],
67
+ resource: [`arn:${partition}:lambda:*:*:function:${constants_1.RENDER_FN_PREFIX}*`],
68
68
  },
69
69
  {
70
70
  id: 'LogsRetention',
71
71
  actions: ['logs:CreateLogGroup', 'logs:PutRetentionPolicy'],
72
72
  resource: [
73
- `arn:aws:logs:*:*:log-group:${constants_1.LOG_GROUP_PREFIX}${constants_1.RENDER_FN_PREFIX}*`,
73
+ `arn:${partition}:logs:*:*:log-group:${constants_1.LOG_GROUP_PREFIX}${constants_1.RENDER_FN_PREFIX}*`,
74
74
  ],
75
75
  },
76
76
  {
77
77
  id: 'FetchBinaries',
78
78
  actions: ['lambda:GetLayerVersion'],
79
- resource: [
80
- hosted_layers_1.REMOTION_HOSTED_LAYER_ARN,
81
- 'arn:aws:lambda:*:580247275435:layer:LambdaInsightsExtension*',
82
- ],
79
+ resource: partition === 'aws-cn'
80
+ ? ['arn:aws-cn:lambda:*:488211338238:layer:LambdaInsightsExtension*']
81
+ : [
82
+ hosted_layers_1.REMOTION_HOSTED_LAYER_ARN,
83
+ 'arn:aws:lambda:*:580247275435:layer:LambdaInsightsExtension*',
84
+ ],
83
85
  },
84
86
  ];
87
+ exports.getRequiredPermissions = getRequiredPermissions;
88
+ exports.requiredPermissions = (0, exports.getRequiredPermissions)('aws');
@@ -26,6 +26,7 @@ type LambdaCommandLineOptions = {
26
26
  ['s3-output-provider-region']: AwsRegion | (string & {}) | undefined;
27
27
  ['s3-output-provider-force-path-style']: boolean;
28
28
  ['custom-role-arn']: string | undefined;
29
+ ['custom-layer-arns']: string | undefined;
29
30
  privacy: Privacy;
30
31
  webhook: string | undefined;
31
32
  ['webhook-secret']: string | undefined;
@@ -21,6 +21,11 @@ const functionsDeploySubcommand = async ({ logLevel, providerSpecifics, fullClie
21
21
  const memorySizeInMb = (_b = args_1.parsedLambdaCli.memory) !== null && _b !== void 0 ? _b : constants_1.DEFAULT_MEMORY_SIZE;
22
22
  const diskSizeInMb = (_c = args_1.parsedLambdaCli.disk) !== null && _c !== void 0 ? _c : constants_1.DEFAULT_EPHEMERAL_STORAGE_IN_MB;
23
23
  const customRoleArn = (_d = args_1.parsedLambdaCli['custom-role-arn']) !== null && _d !== void 0 ? _d : undefined;
24
+ const customLayerArns = args_1.parsedLambdaCli['custom-layer-arns'] === undefined
25
+ ? null
26
+ : args_1.parsedLambdaCli['custom-layer-arns']
27
+ .split(',')
28
+ .map((arn) => arn.trim());
24
29
  const createCloudWatchLogGroup = !args_1.parsedLambdaCli['disable-cloudwatch'];
25
30
  const enableLambdaInsights = (_e = args_1.parsedLambdaCli['enable-lambda-insights']) !== null && _e !== void 0 ? _e : false;
26
31
  const cloudWatchLogRetentionPeriodInDays = (_f = args_1.parsedLambdaCli['retention-period']) !== null && _f !== void 0 ? _f : constants_1.DEFAULT_CLOUDWATCH_RETENTION_PERIOD;
@@ -47,6 +52,7 @@ Version = ${version_1.VERSION}
47
52
  CloudWatch Logging Enabled = ${createCloudWatchLogGroup}
48
53
  CloudWatch Retention Period = ${cloudWatchLogRetentionPeriodInDays} days
49
54
  Lambda Insights Enabled = ${enableLambdaInsights}
55
+ Custom Layers = ${customLayerArns === null ? 'Not specified' : customLayerArns.length}
50
56
 
51
57
  `.trim()));
52
58
  if (vpcSubnetIds) {
@@ -73,6 +79,7 @@ VPC Security Group IDs = ${vpcSecurityGroupIds}
73
79
  cloudWatchLogRetentionPeriodInDays,
74
80
  diskSizeInMb,
75
81
  customRoleArn,
82
+ customLayerArns,
76
83
  enableLambdaInsights,
77
84
  indent: false,
78
85
  logLevel,
@@ -1,10 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.roleSubcommand = exports.ROLE_SUBCOMMAND = void 0;
4
+ const lambda_client_1 = require("@remotion/lambda-client");
4
5
  const suggested_policy_1 = require("../../../api/iam-validation/suggested-policy");
6
+ const get_aws_region_1 = require("../../get-aws-region");
5
7
  const log_1 = require("../../log");
6
8
  exports.ROLE_SUBCOMMAND = 'role';
7
9
  const roleSubcommand = (logLevel) => {
8
- log_1.Log.info({ indent: false, logLevel }, (0, suggested_policy_1.getRolePolicy)());
10
+ const region = (0, get_aws_region_1.getAwsRegion)();
11
+ const { partition } = lambda_client_1.LambdaClientInternals.getAwsRegionMetadata(region);
12
+ log_1.Log.info({ indent: false, logLevel }, (0, suggested_policy_1.getRolePolicy)({ partition }));
9
13
  };
10
14
  exports.roleSubcommand = roleSubcommand;
@@ -1,10 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.userSubcommand = exports.USER_SUBCOMMAND = void 0;
4
+ const lambda_client_1 = require("@remotion/lambda-client");
4
5
  const suggested_policy_1 = require("../../../api/iam-validation/suggested-policy");
6
+ const get_aws_region_1 = require("../../get-aws-region");
5
7
  const log_1 = require("../../log");
6
8
  exports.USER_SUBCOMMAND = 'user';
7
9
  const userSubcommand = (logLevel) => {
8
- log_1.Log.info({ indent: false, logLevel }, (0, suggested_policy_1.getUserPolicy)());
10
+ const region = (0, get_aws_region_1.getAwsRegion)();
11
+ const { partition } = lambda_client_1.LambdaClientInternals.getAwsRegionMetadata(region);
12
+ log_1.Log.info({ indent: false, logLevel }, (0, suggested_policy_1.getUserPolicy)({ partition }));
9
13
  };
10
14
  exports.userSubcommand = userSubcommand;