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

fix(events): AwsApi warns if service does not exist #13352

Merged
merged 9 commits into from Jun 4, 2021
Merged

fix(events): AwsApi warns if service does not exist #13352

merged 9 commits into from Jun 4, 2021

Conversation

mprencipe
Copy link
Contributor

Check against AWS SDK that the given service and action exist. If a service acronym is supplied check if it needs to be uppercased, e.g. rds to RDS. Fixes #13090.


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

@gitpod-io
Copy link

gitpod-io bot commented Mar 2, 2021

@mprencipe
Copy link
Contributor Author

Had to add aws-sdk as a dependency (instead of dev dependency) and include it as a bundled dependency to get the build to pass locally. The build and tests pass locally, got no clue about the NOTICE error in the CodeBuild build.

rix0rrr
rix0rrr previously requested changes Mar 3, 2021
@@ -102,8 +101,12 @@
"@aws-cdk/aws-stepfunctions": "0.0.0",
"@aws-cdk/core": "0.0.0",
"@aws-cdk/custom-resources": "0.0.0",
"constructs": "^3.2.0"
"constructs": "^3.2.0",
"aws-sdk": "^2.848.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not too much of a fan of this.

There are probably just data files we could be copying out of this dependency at build time, no?

In fact, I'm fairly sure there are other modules that are already doing the same. I think probably the AwsCustomResource, which does almost the same as this construct does ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it.


const sdkServiceInstance = new sdkService(apiVersion && { apiVersion });
if (!sdkServiceInstance[action]) {
throw new Error(`The action ${action} for the service ${service} does not exist, check the list of available \
Copy link
Contributor

Choose a reason for hiding this comment

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

The downside of throwing an error is that if our knowledge is incorrect or outdated (for whatever reason, probably because we didn't get the freshest build of the SDK and there's a shiny new API we don't know about yet), the CDK will completely fail to work.

There needs to either be an "I know what I'm doing" override, or this needs to turn into an Annotations.of(this).addWarning().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AwsApi is not a construct so using Annotations.of(this) doesn't work..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about adding the warning to the Lambda handler function?

Copy link
Contributor

Choose a reason for hiding this comment

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

That'll do it, yeah.

let sdkService: any;
let normalizedServiceName: string;

if ((SDK as any)[service]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather do a complete case-insensitive comparison.

Get a list of all services, map the lowercase name of the service to the actual case, and look up in there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it.

@mergify mergify bot dismissed rix0rrr’s stale review March 9, 2021 05:58

Pull request has been modified.

@rix0rrr rix0rrr changed the title fix(events-targets): Check that given AWS API service & action exist fix(events): AwsApi add warning if service does not exist Mar 22, 2021
@rix0rrr rix0rrr changed the title fix(events): AwsApi add warning if service does not exist fix(events): AwsApi warns if service does not exist Mar 22, 2021
@github-actions github-actions bot added the @aws-cdk/aws-events Related to CloudWatch Events label Mar 22, 2021
* @param service Service name
*/
function checkServiceExists(service: string, handler: lambda.SingletonFunction) {
const sdkService = awsSdkMetadata[service.toLowerCase()];
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure this is correct for services like SQS and such? I'm not too familiar with the contents of this map.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This map is generated in buildtools/gen.js. It is built from https://github.com/aws/aws-sdk-js/blob/master/apis/metadata.json

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ping @rix0rrr

rix0rrr
rix0rrr previously approved these changes Apr 22, 2021
@mergify
Copy link
Contributor

mergify bot commented Apr 22, 2021

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

@mergify mergify bot dismissed rix0rrr’s stale review April 23, 2021 19:04

Pull request has been modified.

@gitpod-io
Copy link

gitpod-io bot commented Apr 30, 2021

@mergify
Copy link
Contributor

mergify bot commented Jun 4, 2021

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-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: dd2004c
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify mergify bot merged commit 3bad98f into aws:master Jun 4, 2021
@mergify
Copy link
Contributor

mergify bot commented Jun 4, 2021

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

hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
Check against AWS SDK that the given service and action exist. If a service acronym is supplied check if it needs to be uppercased, e.g. rds to RDS. Fixes aws#13090.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-events-targets): AwsApi service should toUppercase and better error message if not found
3 participants