0

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"
    }, 

1 Answer 1

1

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"
    },
]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.