首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不运行Pulumi?

不运行Pulumi?
EN

Stack Overflow用户
提问于 2022-02-21 10:57:33
回答 1查看 497关注 0票数 3

我正在编写一个使用的烧瓶应用程序。我在跟踪自动化API项目示例。但是当我发送一个POST请求时,我得到了一个程序运行,没有可用的Pulumi引擎;使用pulumi 错误重新运行。自动化API不是应该单独运行CLI吗?

普鲁米CLI可供查阅:

pulumi版本v3.24.1

编辑:我遵循了pulumi示例,这是我的app.py

代码语言:javascript
复制
import pulumi
from flask import Flask, request, make_response, jsonify
from pulumi import automation as auto
import os
from pulumi_aws import s3

app = Flask(__name__)

# This function defines our pulumi s3 static website in terms of the content that the caller passes in.
# This allows us to dynamically deploy websites based on user defined values from the POST body.
def create_pulumi_program(content: str):
    # Create a bucket and expose a website index document

    site_bucket = s3.Bucket("s3-website-bucket", website=s3.BucketWebsiteArgs(index_document="index.html"))
    index_content = content

    # Write our index.html into the site bucket
    s3.BucketObject("index",
                    bucket=site_bucket.id,
                    content=index_content,
                    key="index.html",
                    content_type="text/html; charset=utf-8")

    # Set the access policy for the bucket so all objects are readable
    s3.BucketPolicy("bucket-policy",
                    bucket=site_bucket.id,
                    policy={
                        "Version": "2012-10-17",
                        "Statement": {
                            "Effect": "Allow",
                            "Principal": "*",
                            "Action": ["s3:GetObject"],
                            # Policy refers to bucket explicitly
                            "Resource": [pulumi.Output.concat("arn:aws:s3:::", site_bucket.id, "/*")]
                        },
                    })

    # Export the website URL
    pulumi.export("website_url", site_bucket.website_endpoint)

@app.route('/', methods=['GET'])
def home():
    return "<h1>Hello</p>"


@app.route('/v1/code', methods=['POST'])
def create_handler():
    content = request.get_json()
    project_name = content.get('project_name')
    stack_name = content.get('stack_name')
    pulumi_access_token = request.headers['pulumi_access_token']
    os.environ['PULUMI_ACCESS_TOKEN'] = pulumi_access_token

    try:
        def pulumi_program():
            return create_pulumi_program(content)

        stack = auto.create_stack(stack_name=stack_name,
                                  project_name=project_name,
                                  program=create_pulumi_program(content))
        stack.workspace.install_plugin("aws", "v4.0.0")
        stack.set_config("aws:region", auto.ConfigValue(value="us-west-2"))
        stack.set_config("aws:region", auto.ConfigValue("us-west-2"))
        # deploy the stack, tailing the logs to stdout
        up_res = stack.up(on_output=print)
        return jsonify(id=stack_name, url=up_res.outputs['website_url'].value)
    except auto.StackAlreadyExistsError:
        return make_response(f"stack '{stack_name}' already exists", 409)
    except Exception as exn:
        return make_response(str(exn), 500)

if __name__ == '__main__':
    app.run(debug=True)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-23 08:21:31

我发现了这个问题,因为我在create_stack中将一个参数传递给程序函数。

代码语言:javascript
复制
stack = automation.create_stack(
    stack_name=stack_name, 
    project_name=project_name, 
    program=create_pulumi_program(content)
 )

相反,应该是这样:

代码语言:javascript
复制
stack = automation.create_stack(
     stack_name=stack_name, 
     project_name=project_name, 
     program=create_pulumi_program
)
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71205110

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档