Reputation: 268
I'd like to create an Azure Container Instance from a Javascript-based Azure Function. Unfortunately, I receive an error message:
Result: Failure Exception: The request content was invalid and could not be deserialized: 'Required property 'properties' not found in JSON. Path 'properties.containers[0]', line 1, position 79.'. Stack: RestError: The request content was invalid and could not be deserialized: 'Required property 'properties' not found in JSON. Path 'properties.containers[0]', line 1, position 79.'. at handleErrorResponse (/home/site/wwwroot/node_modules/@azure/core-client/dist/index.js:1321:19) at deserializeResponseBody (/home/site/wwwroot/node_modules/@azure/core-client/dist/index.js:1256:45) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
This is how I want to create the instance using the Azure SDK with @azure/arm-containerinstance package:
async function CreateDockerContainer(var1, var2) {
const subscriptionId = process.env['AZURE_SUBSCRIPTION_ID'].toString();
const resourceGroupName = process.env['RESOURCE_GROUP_NAME'].toString();
const containerInstanceName = 'ContainerAFTest';
const containerImageName = 'xxx.azurecr.io/blender-container:1.0.0';
// const containerName = 'blender-container';
const containerGroupName = 'blender-container-group';
// const containerGroup = new ContainerGroup();
const credential = new DefaultAzureCredential();
const client = new ContainerInstanceManagementClient(credential, subscriptionId);
const containerGroup = {
location: 'westeurope',
containers: [
{
name: containerInstanceName,
properties: {
image: containerImageName,
resources: {
requests: {
cpu: 1.0,
memoryInGB: 3.0
}
},
environmentVariables: [
{
name: 'var1',
value: var1
},
{
name: 'var2',
value: var2
}
]
}
}
],
osType: 'Linux',
restartPolicy: 'Never'
};
const containerInstance = await client.containerGroups.beginCreateOrUpdate(
resourceGroupName,
containerGroupName,
containerGroup
);
console.log('Created container group: ', containerInstance);
const containerResult = containerInstance;
return containerResult;
}
Do I miss something? Thanks
Upvotes: 0
Views: 50
Reputation: 268
I found the solution. The properties was set and that's wrong. Correct is:
const containerGroup = {
location: 'westeurope',
containers: [
{
name: containerInstanceName,
image: containerImageName,
resources: {
requests: {
cpu: 1.0,
memoryInGB: 3.0
}
},
environmentVariables: [
{
name: 'var1',
value: var1
},
{
name: 'var2',
value: var2
}
]
}
],
osType: 'Linux',
restartPolicy: 'Never',
imageRegistryCredentials: [
{
server: 'xxx',
username: xxx,
password: xxx
}
]
};
Upvotes: 0