Closed Devlin556 closed 4 years ago
There is no such concept as public function in API model. It's just shortcut for UI and CLI which will give necessary permissions to invoke functions for all users.
You can achieve that with SDK using such code:
const {FunctionService} = require('yandex-cloud/api/serverless/functions/v1');
const {AccessBindingAction} = require('yandex-cloud/api/access');
const functionService = new FunctionService();
let op = await functionService.updateAccessBindings({
resourceId: "<YOUR FUNCTION ID>",
accessBindingDeltas: [
{
action: AccessBindingAction.ADD,
accessBinding: {
roleId: "serverless.functions.invoker",
subject: { "id": "allUsers", "type": "system" },
}
}
]
});
You will get operation which you should poll using OperationService
until it will be marked done
.
NB: always use updateAccessBinding
(and not setAccessBinding
) to not to rewrite all previously created access bindings.
NB2: you (or your service account) need to have admin
role in given folder to work with access bindings.
How to create cloud function with a public access via SDK?