question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a way to write properties from resources to a file in S3

See original GitHub issue

🚀 feature request

Some way of writing some of the values from resources to a file in S3.

Eg, something like:

const myBucket = new s3.Bucket(this, 'MyBucket');
new s3deploy.BucketDeployment(this, 'MyConfigFile', {
    source: s3deploy.Source.fromString(`{"thisBucketArn": "${myBucket.bucketArn}"}`),
    destinationBucket: myBucket,
    destinationKeyPrefix: 'config.json',
});

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.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:8
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
plumdogcommented, Jul 9, 2019

I did manage to handle this using the rather marvellous AwsCustomResource in @aws-cdk/custom-resources:

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: a) bundling this up a reusable construct b) writing something bespoke (I don’t know enough about the internal to know what that would be) c) documenting this a workaround d) not bothering with either

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.

3reactions
jagregorycommented, Aug 29, 2021

+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).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use custom resources with Amazon S3 buckets in ...
1. Open the CloudFormation console. · 2. Choose Create stack, and then choose With new resources (standard). · 3. In the Specify template...
Read more >
How to load property file from classpath in AWS lambda java
As you want to load a properties file you can use the ResourceBundle to load the properties. ... project/src/main/resources/lambda.properties.
Read more >
Add an Amazon S3 Bucket to the Stack
4.1 Edit the CloudFormation template file · Under the Resources section add the snippet you copied · You do not require any Properties...
Read more >
Setting Up S3 for File Storage - Platform Automation Toolkit
Navigate to the S3 console · Click the "Create bucket" button · Enter a DNS-compliant name for your new bucket. This name must...
Read more >
aws_s3_bucket_object | Resources | hashicorp/aws
bucket - (Required) Name of the bucket to put the file in. Alternatively, an S3 access point ARN can be specified. · key...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found