-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat(s3-deployment): deploy data with deploy-time values #18659
Conversation
Allow deploying test-based content that can potentially include deploy-time values such as attributes of cloud resources. Introduce a `Source.content(objectKey, text)` where `text` can naturally include tokens that resolve only at deploy time. This is implemented by replacing the deploy-time tokens with markers that are replaced inside the s3-deployment custome resource. Fixes #12903 TODO: - [ ] Implement + test the custom resource code - [ ] Documentation - [ ] Finalize integration test
Hi @eladb, FYI I'm currently addressing this like that: new cr.AwsCustomResource(this, 'PutConfig', {
policy: cr.AwsCustomResourcePolicy.fromStatements([
new iam.PolicyStatement({
actions: ['s3:PutObject'],
resources: [props.bucket.arnForObjects('config.json')],
}),
]),
onUpdate: {
service: 'S3',
action: 'putObject',
parameters: {
Bucket: props.bucket.bucketName,
Key: 'config.json',
Body: Stack.of(this).toJsonString(props.config),
ContentType: 'application/json',
CacheControl: 'max-age=0, no-cache, no-store, must-revalidate',
},
physicalResourceId: cr.PhysicalResourceId.of('config'),
},
}); |
@jogold this is very cool, but I since this means the contents of the file is inlined in the template, I think the 1MB limitation of the template size might be a big concern. |
This is correct but one could argue that most of the use cases for files with deploy-time values are small files. Anyway, it's always nice (and fun 😄) to have a generalized solution. |
Definitely interested in this feature as it is developed! A pattern I've run into before that was particularly frustrating is static websites that require deploy-time parameters (say, Cognito user pool information or bucket names). I generally do this through an S3 deployment bucket with a Dockerfile to build the assets. Is this something that could integrate easily with that? Or would the pattern be to render this content separately to the target bucket? |
+1 to this, thank you @eladb ! Looking for this solution right now and glad to see it in development, I use the exact pattern internally but built in is going to be fantastic! |
…m:aws/aws-cdk into benisrae/bucket-deployment-content-source
Co-authored-by: Otavio Macedo <otaviomacedo@protonmail.com>
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
* origin/master: (27 commits) chore(eks): deprecate older versions of EKS (aws#18842) fix(tooling): update vscode devcontainer image (aws#18455) chore: npm-check-updates && yarn upgrade (aws#18832) chore(docs): Fix broken md links (aws#18384) chore(lambda-layer-awscli): install awscli with pip and requirements.txt (aws#18800) fix(aws-appsync): Strip unsupported characters from Lambda DataSource (aws#18765) feat(cfnspec): cloudformation spec v55.0.0 (aws#18827) docs(cfnspec): update CloudFormation documentation (aws#18826) chore(cxapi): plugin context provider limited by cx schema (aws#18709) feat(iotevents): add grant method to Input class (aws#18617) chore(cx-api): break circular dependencies (aws#18767) docs(core): clarify that `addOverride` does not change property casing (aws#18687) feat(s3-deployment): deploy data with deploy-time values (aws#18659) docs(cfnspec): update CloudFormation documentation (aws#18808) feat(cli): `cdk diff` works for Nested Stacks (aws#18207) docs(cfnspec): update CloudFormation documentation (aws#18783) chore(lambda-layer-awscli): add update mechanism for AWS CLI (aws#18780) chore(release): 1.143.0 feat(fsx): add support for FSx Lustre Persistent_2 deployment type (aws#18626) feat(amplify): support performance mode in Branch (aws#18598) ...
Allow deploying test-based content that can potentially include deploy-time values such as attributes of cloud resources. Introduce a `Source.data(objectKey, text)` and `Source.jsonData(objectKey, obj)` where the data can naturally include deploy-time tokens such as references to resources (`Ref`) or to resource attributes (`Fn::GetAtt`). For example: ```ts const appConfig = { topic_arn: topic.topicArn, base_url: 'https://my-endpoint', }; new s3deploy.BucketDeployment(this, 'BucketDeployment', { sources: [s3deploy.Source.jsonData('config.json', config)], destinationBucket: destinationBucket, }); ``` This is implemented by replacing the deploy-time tokens with markers that are replaced inside the s3-deployment custom resource. Fixes aws#12903 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@eladb I tried to use it with REST Api url and I get:
I'm doing something wrong here, because your changes should make that possible. |
Allow deploying test-based content that can potentially include deploy-time values such as attributes of cloud resources.
Introduce a
Source.data(objectKey, text)
andSource.jsonData(objectKey, obj)
where the data can naturally include deploy-time tokens such as references to resources (Ref
) or to resource attributes (Fn::GetAtt
).For example:
This is implemented by replacing the deploy-time tokens with markers that are replaced inside the s3-deployment custom resource.
Fixes #12903
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license