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
Conversation
…xist during synth. Fixes #13090.
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. |
@@ -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" |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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 \ |
There was a problem hiding this comment.
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()
.
There was a problem hiding this comment.
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..
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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]) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.
* @param service Service name | ||
*/ | ||
function checkServiceExists(service: string, handler: lambda.SingletonFunction) { | ||
const sdkService = awsSdkMetadata[service.toLowerCase()]; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping @rix0rrr
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). |
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). |
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*
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