Skip to content
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): create DeployTimeSubstitutedFile to allow substitutions in file #25876

Merged
merged 26 commits into from
Jun 16, 2023

Conversation

sumupitchayan
Copy link
Contributor

@sumupitchayan sumupitchayan commented Jun 6, 2023

Closes #1461

The DeployTimeSubstitutedFile construct allows you to upload a file and specify substitutions to be made in it, which will be resolved during deployment.

For example, if you wanted to create a REST API from a Swagger file spec but want to reference other CDK resources in your API spec, you can now do so in-line:

const bucket: Bucket;
const myLambdaFunction: lambda.Function;

const deployment = new s3deploy.DeployTimeSubstitutedFile(this, 'MyApiFile', {
  source: 'my-swagger-spec.yaml',
  destinationBucket: bucket,
  substitutions: {
    xxxx: myLambdaFunction.functionArn,
    yyyy: 'mySubstitution',
  },
});

const api = new apigateway.SpecRestApi(this, 'books-api', {
  apiDefinition: apigateway.ApiDefinition.fromBucket(deployment.bucket, deployment.objectKey),
});

Where 'xxxx' and 'yyyy' are the examples of placeholder text you can add in your local file spec to be substituted by surrounding the placeholder with double curly braces, for example writing: {{ xxxx }} in your file where you want a substitution.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
@gitpod-io
Copy link

gitpod-io bot commented Jun 6, 2023

@aws-cdk-automation aws-cdk-automation requested a review from a team June 6, 2023 21:55
@github-actions github-actions bot added effort/large Large work item – several weeks of effort feature-request A feature should be added or improved. p1 labels Jun 6, 2023
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jun 6, 2023
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

sumupitchayan and others added 9 commits June 6, 2023 21:15
Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
…{{ brackets }} in the local file

Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
@aws-cdk-automation aws-cdk-automation dismissed their stale review June 8, 2023 15:23

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
…assed in

Signed-off-by: Sumu <sumughan@amazon.com>
@sumupitchayan sumupitchayan marked this pull request as ready for review June 9, 2023 04:12
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jun 9, 2023
sumupitchayan and others added 2 commits June 9, 2023 09:29
Co-authored-by: Otavio Macedo <288203+otaviomacedo@users.noreply.github.com>
Signed-off-by: Sumu <sumughan@amazon.com>
@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jun 9, 2023
Signed-off-by: Sumu <sumughan@amazon.com>
sumupitchayan and others added 6 commits June 14, 2023 12:20
Signed-off-by: Sumu <sumughan@amazon.com>
…d that it does not double substitute variables

Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 75aeab6
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Jun 16, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit ca2e6a2 into main Jun 16, 2023
@mergify mergify bot deleted the sumughan/feat-deploytimesubstitutedfile branch June 16, 2023 08:01
@ChrisLane
Copy link

This is great. Could the same be done for an aws_s3.Asset?

My use-case is that I have a third-party construct that accepts an S3 path for a script to run.
I have an Asset that deploys the script and I pass the S3 path from that to the third-party construct but then within the script I need to download a file that itself is deployed to S3 via CDK. This is why I need the replacement in the asset, to maintain the dependency to replace the construct when either of the files change.

@alex-cook-finres
Copy link

Does this actually work as-is or does it need other changes? If I actually substitute any parameters I end up getting an "Invalid OAS input" failure error. If I hard-code values with the same code (just no substitutions in the file) it works fine. Any help would be great as this seems like a nice way to actually use my API spec compared to other options I've seen out there.

    const deployment = new s3deploy.DeployTimeSubstitutedFile(
      this,
      "MyApiFile",
      {
        source: path.join(__dirname, "../../openapi-spec/api-definition.yaml"),
        destinationBucket: bucket,
        destinationKey: "api-definition.yaml",
        substitutions: {
          LAMBDA_ARN: lambdaFunction.functionArn,
          AWS_REGION: this.region,
        },
      }
    );

    const api = new apigateway.SpecRestApi(this, "CdkApi", {
      apiDefinition: apigateway.ApiDefinition.fromBucket(
        deployment.deployedBucket, // also tried with deployment.bucket
        deployment.objectKey
      ),
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS. effort/large Large work item – several weeks of effort feature-request A feature should be added or improved. p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parameterized swagger support for API gateway
5 participants