-
Notifications
You must be signed in to change notification settings - Fork 4k
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-targets): AwsApi fails when SDKv3 Command expects Uint8Array #27034
Conversation
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 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.
cf80c07
to
f31a8d0
Compare
f31a8d0
to
a0953ec
Compare
packages/@aws-cdk/sdk-v2-to-v3-adapter/lib/coerce-api-parameters.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/sdk-v2-to-v3-adapter/lib/coerce-api-parameters.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/sdk-v2-to-v3-adapter/lib/coerce-api-parameters.ts
Outdated
Show resolved
Hide resolved
48c9c34
to
41d3631
Compare
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
af6c178
to
e744212
Compare
e744212
to
83158ea
Compare
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 main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
…t8Array The SDKv3 has changed the input representation of `blob` types from `string | Buffer | Uint8Array` to `Uint8Array`. That means all places where customers were passing in `strings` now fail to pass the right kind of value. Similar to #27034, but for `AwsCustomResource`.
…t8Array The SDKv3 has changed the input representation of `blob` types from `string | Buffer | Uint8Array` to `Uint8Array`. That means all places where customers were passing in `strings` now fail to pass the right kind of value. Similar to #27034, but for `AwsCustomResource`.
…t8Array (#27065) The SDKv3 has changed the input representation of `blob` types from `string | Buffer | Uint8Array` to `Uint8Array`. That means all places where customers were passing in `strings` now fail to pass the right kind of value. Similar to #27034, but for `AwsCustomResource`. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
…ay (#27034) In #27002 we have migrated the AwsApi Construct to SDKv3. However some SDKv3 Commands expect a `Uint8Array` in places where SDKv2 previously would accept a `string`. This is a problem because handler input is passed directly into the SDK calls and the input can only contain JSON data types. To solves this, we keep a list of SDK actions and parameters that should be coerced to `Uint8Array`. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
…t8Array (#27065) The SDKv3 has changed the input representation of `blob` types from `string | Buffer | Uint8Array` to `Uint8Array`. That means all places where customers were passing in `strings` now fail to pass the right kind of value. Similar to #27034, but for `AwsCustomResource`. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
## Description The following issue reports an error that occurs when calling an API that takes the `Date` type as a parameter, such as `GetMetricData` API, from a Custom Resource Lambda function, where the parameter is passed as `string` type to the AWS SDK. #27962 https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/cloudwatch/command/GetMetricDataCommand/#:~:text=Description-,EndTime,-Required To resolve this error, the `string` type must be properly converted to `Date` type when calling the AWS SDK from Lambda. In this PR, I added the conversion to Date type in the same way as the existing conversion to `number` and `Uint8Array` types. `Uint8Array`: #27034 `number`: #27112 ## Major changes ### `update-sdkv3-parameters-model.ts` script If the type is `timestamp` in the `smithy` specification, write `d` to the state machine so that it can be converted to a Date type later. https://smithy.io/2.0/spec/simple-types.html#timestamp `update-sdkv3-parameters-model.sh` script was not called from anywhere, so I called it manually and updated the JSON file. Please let me know if there is a problem. ### `sdk-v2-to-v3-adapter` module I added code to convert value marked `d` in state machine to `Date` type. If the conversion to `Date` type fails, the `Date` class does not throw an exception, so the error is handled in a slightly tricky way. Also added a unit test for this process. ### `integ-tests-alpha` module Added integ-test to verify that errors reported in the related issue have been resolved. The IAM Policy added internally by the call to `adPolicyStatementFromSdkCall` looks like the following and does not call `GetMetricData` correctly, so the `addToRolePolicy` method was used to explicitly add a new Policy is added explicitly with the `addToRolePolicy` method. ```json { "Version": "2012-10-17", "Statement": [ { "Action": [ "monitoring:GetMetricData" ], "Resource": [ "*" ], "Effect": "Allow" } ] } ``` https://github.com/aws/aws-cdk/blob/1a9c30e55e58203bd0a61de82711cf10f1e04851/packages/aws-cdk-lib/custom-resources/lib/helpers-internal/sdk-v3-metadata.json#L174 fixes #27962 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
In #27002 we have migrated the AwsApi Construct to SDKv3.
However some SDKv3 Commands expect a
Uint8Array
in places where SDKv2 previously would accept astring
.This is a problem because handler input is passed directly into the SDK calls and the input can only contain JSON data types.
To solves this, we keep a list of SDK actions and parameters that should be coerced to
Uint8Array
.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license