'Unzip artifact for REST API Gateway in CDK
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
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | lynkfox |
