Reputation: 51
I am using the following code to create a stack from servicecatalog and putting hardcoded value under "provisoningParameters":
from flask import Flask
import time
import boto3
from flask import Flask
from flask import request
from flask import jsonify, make_response
import requests
import json
import argparse
app = Flask(__name__)
@app.route('/createstack', methods=['POST'])
def post_createstack():
content = request.get_json(force = True)
response = createstack(content['ProductId'], content['ProvisionedProductName'], content['JsonFileName'])
return make_response(str(response), 200)
def cluster(ProductId, ProvisionedProductName):
try:
client = boto3.client('servicecatalog', region_name='us-east-1')
ProvisioningArtifactId = client.list_provisioning_artifacts(ProductId=ProductId)
ArtifactId = ProvisioningArtifactId['ProvisioningArtifactDetails'][0]['Id']
response = client.provision_product(ProductId=ProductId, ProvisionedProductName=ProvisionedProductName, ProvisioningArtifactId=ArtifactId, ProvisioningParameters=JsonFileName)
print(response)
return response
except Exception as e:
error = "An error occurred processing this request: " + str(e)
return(error)
if __name__ == '__main__':
app.debug = True
app.run(host='0.0.0.0', port=8080)
curl -X POST -d '{"ProductId": "prod-ua5lk7mbx436q", "ProvisionedProductName": "test-pipeline", "JsonFileName": "devops-pipeline-params.json"}' http://0.0.0.0:8080/createstack
And i am getting error
An error occurred processing this request: Parameter validation failed:
Invalid type for parameter ProvisioningParameters, value: devops-pipeline-params.json, type: <class 'str'>, valid types: <class 'list'>, <class 'tuple'>
Now i have put all those values in json file and store the file to the same location where above script stored (service.py)
I kept following variable in "devops-pipeline-params.json"
{
"ParameterValue": "Standard",
"ParameterKey": "ServiceProfile"
},
{
"ParameterValue": "External",
"ParameterKey": "BuildLocation"
},
{
"ParameterValue": "Disabled",
"ParameterKey": "SoapUIEnabled"
},
Upvotes: 0
Views: 148
Reputation: 974
Your error message is giving you a great clue to the answer: Invalid type for parameter ProvisioningParameters, value: devops-pipeline-params.json, type: <class 'str'>, valid types: <class 'list'>, <class 'tuple'>
So the valid types are either <class 'list'>, <class 'tuple'>
, which incidentally means that you have formatted your devops-pipeline-params.json
incorrectly. According to the documentation you are very close, just make it into 3 lists like this:
[
{
"Value": "Standard",
"Key": "ServiceProfile"
}
],
[
{
"Value": "External",
"Key": "BuildLocation"
}
],
[
{
"Value": "Disabled",
"Key": "SoapUIEnabled"
},
]
Upvotes: 1