addLayerVersionPermission method

Future<AddLayerVersionPermissionResponse> addLayerVersionPermission({
  1. required String action,
  2. required String layerName,
  3. required String principal,
  4. required String statementId,
  5. required int versionNumber,
  6. String? organizationId,
  7. String? revisionId,
})

Adds permissions to the resource-based policy of a version of an AWS Lambda layer. Use this action to grant layer usage permission to other accounts. You can grant permission to a single account, all AWS accounts, or all accounts in an organization.

To revoke permission, call RemoveLayerVersionPermission with the statement ID that you specified when you added it.

May throw ServiceException. May throw ResourceNotFoundException. May throw ResourceConflictException. May throw TooManyRequestsException. May throw InvalidParameterValueException. May throw PolicyLengthExceededException. May throw PreconditionFailedException.

Parameter action : The API action that grants access to the layer. For example, lambda:GetLayerVersion.

Parameter layerName : The name or Amazon Resource Name (ARN) of the layer.

Parameter principal : An account ID, or * to grant permission to all AWS accounts.

Parameter statementId : An identifier that distinguishes the policy from others on the same layer version.

Parameter versionNumber : The version number.

Parameter organizationId : With the principal set to *, grant permission to all accounts in the specified organization.

Parameter revisionId : Only update the policy if the revision ID matches the ID specified. Use this option to avoid modifying a policy that has changed since you last read it.

Implementation

Future<AddLayerVersionPermissionResponse> addLayerVersionPermission({
  required String action,
  required String layerName,
  required String principal,
  required String statementId,
  required int versionNumber,
  String? organizationId,
  String? revisionId,
}) async {
  ArgumentError.checkNotNull(action, 'action');
  ArgumentError.checkNotNull(layerName, 'layerName');
  _s.validateStringLength(
    'layerName',
    layerName,
    1,
    140,
    isRequired: true,
  );
  ArgumentError.checkNotNull(principal, 'principal');
  ArgumentError.checkNotNull(statementId, 'statementId');
  _s.validateStringLength(
    'statementId',
    statementId,
    1,
    100,
    isRequired: true,
  );
  ArgumentError.checkNotNull(versionNumber, 'versionNumber');
  final $query = <String, List<String>>{
    if (revisionId != null) 'RevisionId': [revisionId],
  };
  final $payload = <String, dynamic>{
    'Action': action,
    'Principal': principal,
    'StatementId': statementId,
    if (organizationId != null) 'OrganizationId': organizationId,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri:
        '/2018-10-31/layers/${Uri.encodeComponent(layerName)}/versions/${Uri.encodeComponent(versionNumber.toString())}/policy',
    queryParams: $query,
    exceptionFnMap: _exceptionFns,
  );
  return AddLayerVersionPermissionResponse.fromJson(response);
}