我正在尝试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。
答案 0 :(得分:0)
尝试定义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
)