-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a way to write properties from resources to a file in S3 #3257
Comments
Some more digging suggests to me that this might not be possible at present by hacking at assets, as assets are copied to a staging directory ( |
This should help you get some of the way. It doesn't seem to support dynamically writing content, but it does support writing a file you have locally to an s3 bucket of your choice. If it were me, I would write the contents to the "Metadata" of a resource, which would give you the feature of allowing the metadata to be Fn::Sub'd (and therefore ${myBucket.bucketArn} would be evaluated). Then I'd have a lambda read from that resource's metadata and put it into an S3 bucket. This is, from a high level, exactly how cfn-init works - it reads the Fn::Sub'd text from a resource's Metadata. |
I did manage to handle this using the rather marvellous const config = {
myBucketArn = myBucket.bucketArn,
};
new customResources.AwsCustomResource(this, 'WriteS3ConfigFile', {
onUpdate: {
service: 'S3',
action: 'putObject',
parameters: {
Body: JSON.stringify(config),
Bucket: myBucket.bucketName,
Key: 'config.json',
},
physicalResourceId: Date.now().toString(), // always write this file
},
// we need this because we're not doing conventional resource creation
policyStatements: [
new iam.PolicyStatement({
actions: ['s3:PutObject'],
resources: [`${myBucket.bucketArn}/config.json`],
}),
],
}); Whether the right thing to do is: I'm not sure. I suppose if this is functionality that lots of people might require, then a or b. If only a few, then c. If very very few (or just me), then d. |
It's not S3, so I don't know how hard your requirement is on that, but the SSM Parameter Store is intended exactly for storing this kind of configuration data. |
I created a class that allows you to provide a template for a JSON config file that you would like to be written to S3, for use with static website deployments. How it works...
Basic Example
Full working example and source code for lambda functionhttps://gist.github.com/djorg83/11fc8cba5c37c9c7d89b108f9e42d2db |
@djorg83 The We are currently actively working on redesigning (which we would love feedback on) the CloudFront module. As part of that work, we are considering vending an L3 library that makes it super easy to implement the Until then, I suggest you publish this as a third-party reusable library. You already have the code ready, and it should be fairly easy to setup the publishing scaffolding, see Publishing Modules. I'll also be happy to offer a review on that code and help in any way I can. Thoughts? |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
Don't close |
Closing this for now as there doesn't seem to be any more actionable steps. Here's a link to the Cloudfront tracking issue and redesign RFC. Feel free to reopen. |
Reopening. I've just ran into the need for this as well, and I actually feel that the |
+1 I think the s3 deployment would be a good place for this too. I'm uploading a bunch of files with a deployment, but I'd like one of them to be templated with information from the deployment (think environment name, S3 bucket URL etc). |
I've been experimenting with something like this. Will report back in the coming weeks with some ideas. |
I have a similar use case, local directory of template files i want to substitute configs into and upload to S3. There is also this ticket, but it is for a subtly different thing: #12903 |
I like the idea of And I think this sort-a exists already, but it's not a published package, just an example: |
🚀 feature request
Some way of writing some of the values from resources to a file in S3.
Eg, something like:
should deploy the bucket, then write the ARN of the bucket to the json file in the bucket at
config.json
.I suspect there's a way to do this already by abusing assets sufficiently, but I haven't been able to make it work. The closest I can get is to write the variables into the source for a lambda and access them using API gateway, but that seems silly.
The text was updated successfully, but these errors were encountered: