在 CDK 中解压 REST API 网关的工件

发布于 2025-01-13 09:27:00 字数 621 浏览 0 评论 0原文

我当前正在通过 parameterOverrides 传递 S3 存储桶名称和对象密钥。 但是,key 实际上是一个压缩文件(包含 YAML):

export class BusinessAssetApi extends SpecRestApi {
  constructor(scope: Construct, id: string, bucketName: string, key: string) {
    const bucket = Bucket.fromBucketName(scope, "openapi-bucket", bucketName)
    super(scope, id, {
      deploy: true,
      deployOptions: {
        stageName: STAGE_NAME,
      },
      apiDefinition: ApiDefinition.fromBucket(bucket, key),
    })
  }
}

现在,我想知道是否有一种聪明的方法来解压缩文件并获取 yaml 文件,或者是否有是否有一种更智能的方法来保存具有特定文件名和/或文件扩展名的工件?

TIA

票价

I'm currently passing, thru parameterOverrides, both the S3 Bucket name and the object key.
However, the key is in fact a zipped file (that contains the YAML):

export class BusinessAssetApi extends SpecRestApi {
  constructor(scope: Construct, id: string, bucketName: string, key: string) {
    const bucket = Bucket.fromBucketName(scope, "openapi-bucket", bucketName)
    super(scope, id, {
      deploy: true,
      deployOptions: {
        stageName: STAGE_NAME,
      },
      apiDefinition: ApiDefinition.fromBucket(bucket, key),
    })
  }
}

Now, I want to know if there's a smart way to unzip the file and get the yaml file instead, or if there is a smarter way to save the artifact with a specific filename and/or file extension?

TIA

FAres

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清醇 2025-01-20 09:27:00

fromBucket 适用于将配置文件或其他所需文件直接存储在 s3 存储桶中的情况 - 它们并不是真正用于工件(我有点假设您是从 codePipeline 中的早期步骤获取此工件?) - 因此,您遇到了这种设计的主要缺点 - zip 文件不是配置,并且 fromBucket 不会解压缩。

如果您有一个存储库作为基点,并且它是您的管道的一部分或者您运行 cdk 部署的位置,则可以使用 fromAsset 代替,但这在获取方面有点复杂文件在那里。

在这种情况下,我知道的唯一解决方案是将文件作为管道进程的一部分直接存储在 s3 存储桶中,然后将其作为参数的一部分传递到下一个堆栈中。

我想,如果您确实没有其他选择,您可以编写一些代码来从工件中获取 zip 并从管道事件中获取它的密钥,将其解压缩在代码中,然后使用 fromInline< /code> 相反...但这可能不会按预期工作。

fromBucket is intended for use where you are storing your configuration files or other needed files directly in an s3 bucket - they aren't really intended for an artifact (i am kinda assuming you are getting this artifact from an earlier step in a codePipeline?) - and as such you have encountered the primary drawback of this design - zip files are not the configuration, and fromBucket does not unzip.

if you have a repo as your base point, and it's part of your pipeline or where you are running cdk deploy from, you can use fromAsset instead, but this is a bit more convoluted in terms of getting that file there.

The only solution I know of in this situation is to store the file as part of your pipeline process directly in an s3 bucket and then pass that as part of your parameters into your next stack.

I suppose alternatively, if you really have no other choice, you could write a bit of code to grab the zip out of the artifact and the keys for it out of the pipeline event, unzip it in code, and use fromInline instead... but that probably wont work as expected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文