创建对象后如何调用函数?
How to call a function when an Object has been created?
我正在试用 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 似乎没有让我说 'call this function after s3 bucket is created'.
有人知道怎么做吗?否则我会回到 Terraform。
尝试定义 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
)
我正在试用 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 似乎没有让我说 'call this function after s3 bucket is created'.
有人知道怎么做吗?否则我会回到 Terraform。
尝试定义 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
)