I have API Gateway integrated with s3:
s3Integration = (props: CustomApiGatewayProps): AwsIntegration => {
const accessRole = new Role(this, 'accessRole', {
assumedBy: new ServicePrincipal('apigateway.amazonaws.com'),
inlinePolicies: {
{...policy to put object to s3 bucket...}
},
});
return new AwsIntegration({
service: 's3',
integrationHttpMethod: 'PUT',
path: `${props.customBucket.bucketName}/{key}`,
options: {
credentialsRole: accessRole,
integrationResponses: [
{
statusCode: '200',
responseTemplates: {
'application/xml': `
<ID>$context.requestId</ID>
`,
},
},
],
requestParameters: {
'integration.request.path.key': 'method.request.path.key',
},
},
});
};
Calling api endpoint triggers putting object into s3 bucket. I'd like to send a response to the client with requestID taken from api gateway. This is a part which works. But I also want to add this requestID to the newly created s3 bucket as a tag. Do you have any idea how can I configure it? It is AWS CDK written in typescript. I tried this:
requestTemplates: {
'application/json': JSON.stringify({
Tagging: 'RequestId=$context.requestId',
}),
},
but it overrides body sent by client.