I'm trying to use the Yandex.Cloud function API from bash and cURL.
In order to do that, I'm composing a JSON like this:
#Make header
IAM_TOKEN="myToken"
HEADER="Authorization: Bearer ${IAM_TOKEN}"
#Make data JSON
DATA=""
for ELEMENT in \
"'"\
'{"runtime":"dotnetcore31", "entrypoint": "Function.Handler",'\
'"resources":{"memory":"134217728"}, "content": "PLACEHOLDERFORCONTENT",'\
'"ServiceAccountId":"accId", '\
'"function_id": "funcId"}'\
"'"; do
DATA+="${ELEMENT}"
done
Then, I need to supply content of the deployment package inside JSON, as API suggests:
In my case, it is a zip archive with function code. So, I read the file as bytes and inject the result into the JSON string. And send the request.
#Read file content
FILE_LOC="/Users/Constantine/Downloads/archiveName.zip"
FILE_BYTES=`(xxd -b ${FILE_LOC}) | base64`
#Inject content into JSON
DATA=${DATA/PLACEHOLDERFORCONTENT/$FILE_BYTES}
#Send the request
eval "$(echo curl -H \"$HEADER\" --data-binary $DATA https://serverless-functions.api.cloud.yandex.net/functions/v1/versions)"
Here, I'm getting the -bash: /usr/bin/curl: Argument list too long error. I suspect this happens because cURL interprets the binary content as the filename to read, but I'm not sure how to resolve this.
How can I supply binary content from a file into a JSON string?