aws-sdk-js-v3
aws-sdk-js-v3 copied to clipboard
Incorrect XML payload is generated when issuing a "PutBucketLifecycleConfiguration" s3 api
Describe the bug
When we try to update the bucket lifecycle rules by using PutBucketLifecycleConfigurationCommand
it generates an incorrect root node in the xml payload. The root node is called as BucketLifecycleConfiguration
instead of LifecycleConfiguration
as mentioned in the api docs. The issue is in the generated client.
Your environment
SDK version number
@aws-sdk/[email protected]
The issue seems to be valid even for the recent versions.
Is the issue in the browser/Node.js/ReactNative?
Browser/Node.js/ReactNative
Details of the browser/Node.js/ReactNative version
v10.17.0
Steps to reproduce
- Use
PutBucketLifecycleConfigurationCommand
to save some lifecycle rules for a bucket:
async function saveRules(bucketName, rules = []) {
const data = await client.send(new PutBucketLifecycleConfigurationCommand({
Bucket: bucketName,
LifecycleConfiguration: {
Rules: rules
}
}));
return data;
}
Observed behavior
The xml payload is generated incorrectly:
<?xml version="1.0" encoding="UTF-8"?>
<BucketLifecycleConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Rule>
<Expiration>
<Days>34</Days>
</Expiration>
<ID>test-rule-1</ID>
<Filter>
<Prefix>p1/</Prefix>
</Filter>
<Status>Enabled</Status>
</Rule>
</BucketLifecycleConfiguration>
Expected behavior
Payload should be:
<?xml version="1.0" encoding="UTF-8"?>
<LifecycleConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Rule>
<Expiration>
<Days>34</Days>
</Expiration>
<ID>test-rule-1</ID>
<Filter>
<Prefix>p1/</Prefix>
</Filter>
<Status>Enabled</Status>
</Rule>
</LifecycleConfiguration>
This is being looked at internally. Thanks so much for the bug report. I'll keep these tickets updated as I get more information that I can share
Submitted patch #2162
Should this be a bug?
The shape name for LifeCycleConfiguration is BucketLifeCycleConfiguration even in v2 https://github.com/aws/aws-sdk-js/blob/17245a8c612ddd3cfe01b0c45e70cfbb557b62d1/apis/s3-2006-03-01.normal.json#L7842-L7855
I visited this issue while analyzing model updates for clients in https://github.com/aws/aws-sdk-js-v3/pull/2258
Verified that LifeCycleConfiguration is added in Bucket in both cases:
- When payload is
<LifecycleConfiguration>
- When payload is
<BucketLifecycleConfiguration>
Code changed in https://github.com/aws/aws-sdk-js-v3/blob/da2c0852df6bc64cbd397489f2a8d1aea5d88c6f/clients/client-s3/protocols/Aws_restXml.ts#L10193 The body tag console.log at https://github.com/aws/aws-sdk-js-v3/blob/da2c0852df6bc64cbd397489f2a8d1aea5d88c6f/clients/client-s3/protocols/Aws_restXml.ts#L3439
Code used for testing
const { S3, waitForBucketExists } = require("@aws-sdk/client-s3");
(async () => {
const region = "us-west-2";
const client = new S3({ region });
const Bucket = `test-bucket-${Date.now()}`;
await client.createBucket({ Bucket });
await waitForBucketExists({ client }, { Bucket });
await client.putBucketLifecycleConfiguration({
Bucket,
LifecycleConfiguration: {
Rules: [
{
Expiration: {
Days: 7,
},
Filter: {
Prefix: "",
},
Status: "Enabled",
},
],
},
});
console.log(await client.getBucketLifecycleConfiguration({ Bucket }));
await client.deleteBucketLifecycle({ Bucket });
await client.deleteBucket({ Bucket });
})();
console.log output for body
<?xml version="1.0" encoding="UTF-8"?><BucketLifecycleConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Rule><Expiration><Days>7</Days></Expiration><Filter><Prefix></Prefix></Filter><Status>Enabled</Status></Rule></BucketLifecycleConfiguration>
<?xml version="1.0" encoding="UTF-8"?><LifecycleConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Rule><Expiration><Days>7</Days></Expiration><Filter><Prefix></Prefix></Filter><Status>Enabled</Status></Rule></LifecycleConfiguration>
Verified that v2 sends LifeCycleConfiguration
by console.log req.httpRequest.body
in populateBody
https://github.com/aws/aws-sdk-js/blob/17245a8c612ddd3cfe01b0c45e70cfbb557b62d1/lib/protocol/rest_xml.js#L26
Code
const AWS = require("aws-sdk");
(async () => {
const region = "us-west-2";
const client = new AWS.S3({ region });
const Bucket = `test-bucket-${Date.now()}`;
await client.createBucket({ Bucket }).promise();
await client.waitFor("bucketExists", { Bucket }).promise();
await client
.putBucketLifecycleConfiguration({
Bucket,
LifecycleConfiguration: {
Rules: [
{
Expiration: {
Days: 7,
},
Filter: {
Prefix: "",
},
Status: "Enabled",
},
],
},
})
.promise();
console.log(
await client.getBucketLifecycleConfiguration({ Bucket }).promise()
);
await client.deleteBucket({ Bucket }).promise();
})();
Output
<LifecycleConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Rule><Expiration><Days>7</Days></Expiration><Filter><Prefix></Prefix></Filter><Status>Enabled</Status></Rule></LifecycleConfiguration>
The v2 uses LifecycleConfiguration
as it uses payloadMember.name
building XmlNode:
- https://github.com/aws/aws-sdk-js/blob/17245a8c612ddd3cfe01b0c45e70cfbb557b62d1/lib/protocol/rest_xml.js#L17-L18
- https://github.com/aws/aws-sdk-js/blob/17245a8c612ddd3cfe01b0c45e70cfbb557b62d1/lib/xml/builder.js#L7-L12
The fix is to be added in XmlShapeSerVisitor https://github.com/aws/aws-sdk-js-v3/blob/da2c0852df6bc64cbd397489f2a8d1aea5d88c6f/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/XmlShapeSerVisitor.java#L195-L196
The bug exists in serializing structure where codegen tries to read XmlName trait https://github.com/aws/aws-sdk-js-v3/blob/da2c0852df6bc64cbd397489f2a8d1aea5d88c6f/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/XmlShapeSerVisitor.java#L190-L193
Confirmed that the xmlName trait is present on LifecycleConfiguration https://github.com/aws/aws-sdk-js-v3/blob/4f9f4a79b019c1c35530e05c4138fde88a6fb547/codegen/sdk-codegen/aws-models/s3.2006-03-01.json#L9558-L9566
Smithy documentation on xmlName trait https://awslabs.github.io/smithy/1.0/spec/core/xml-traits.html#xmlname-trait
I have the same issue working against AWS S3 (rather than something API-compatible etc.)
@alexforsyth @ajredniwja Is this going to be fixed? Its still broken in the latest client and judging from the reports seems to have been broken for over 6 months?
Greetings! We’re closing this issue because it has been open a long time and hasn’t been updated in a while and may not be getting the attention it deserves. We encourage you to check if this is still an issue in the latest release and if you find that this is still a problem, please feel free to comment or open a new issue.
What a great way to deal with bugs 😂 Wait long enough and pretend its not a problem any more.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.