0

我正在尝试 Pulumi 并创建一个 Elasticbeanstalk 设置,它使用 s3 存储桶来存储应用程序版本工件。

Pulumi 抱怨在创建“ApplicationVersion”时发布工件不在 s3 存储桶上

Updating (testing-stack):

     Type                                        Name                        Status                  Info
     pulumi:pulumi:Stack                         webserver-py-testing-stack  **failed**              1 error
 +   └─ aws:elasticbeanstalk:ApplicationVersion  dev-app-name                **creating failed**     1 error

Diagnostics:
  aws:elasticbeanstalk:ApplicationVersion (dev-app-name):
    error: Plan apply failed: InvalidParameterCombination: Unable to download from S3 location (Bucket: app-name-releases  Key: release2.zip). Reason: Not Found
        status code: 400, request id: e7d4a07e-f55b-4a13-a4cf-fe971982a441

  pulumi:pulumi:Stack (webserver-py-testing-stack):
    error: update failed

Resources:
    4 unchanged

Duration: 6s

pulumi python 配置

releases_bucket = s3.Bucket(
    resource_name=RELEASES_BUCKET,
    bucket=RELEASES_BUCKET,
)

def upload_release_zip(path, bucket_id):
    s3 = boto3.client('s3')
    s3.upload_file(Filename=str(path), Bucket=bucket_id, Key=path.name)


upload_release_zip = partial(upload_release_zip, path=Path('release2.zip'))

releases_bucket.id.apply(upload_release_zip)

application = Application(resource_name=ENV_APP_NAME, name=ENV_APP_NAME)

repository = ecr.Repository(resource_name=APP_NAME, name=APP_NAME)

app_version = ApplicationVersion(
    resource_name=ENV_APP_NAME,
    application=application,
    bucket=releases_bucket.id,
    key='release2.zip',
)
environment = Environment(
    application=application,
    resource_name=ENV_APP_NAME,
    name=ENV_APP_NAME,
    solution_stack_name=STACK,
    settings=BEANSTALK_ENVIRONMENT_SETTINGS,
    wait_for_ready_timeout=BEANSTALK_ENVIRONMENT_TIMEOUT,
    version=app_version,
)

请注意releases_bucket.id.apply(upload_release_zip),在上面,我这样做是为了在 ApplicationVersion 发生之前尝试调用上传函数,但它似乎不起作用。文档https://pulumi.io/reference/programming-model/#outputs似乎没有让我说“在创建 s3 存储桶后调用此函数”。

有谁知道这是怎么做到的吗?否则我会回到 Terraform。

4

1 回答 1

1

尝试定义BucketObject资源而不是手动上传文件。符合的东西

# upload_release_zip removed

obj = s3.BucketObject('release2.zip',
    bucket=releases_bucket.id,
    source=FileAsset('./release2.zip'))

app_version = elasticbeanstalk.ApplicationVersion(
    resource_name=ENV_APP_NAME,
    application=application,
    bucket=releases_bucket.id,
    key=obj.key
)
于 2019-06-13T14:58:10.587 回答