This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Outputs": { | |
"bucketArn": { | |
"Value": { | |
"Fn::ImportValue": "exp:ExportsOutputFnGetAttExportedBucket5C9669B4ArnA5E36DA6" | |
} | |
} | |
}, | |
"Resources": { | |
"CDKMetadata": {...} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Resources": { | |
"ExportedBucket5C9669B4": { | |
"Type": "AWS::S3::Bucket", | |
"UpdateReplacePolicy": "Retain", | |
"DeletionPolicy": "Retain", | |
"Metadata": { | |
"aws:cdk:path": "exp/ExportedBucket/Resource" | |
} | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class ExportingStack extends Stack { | |
public readonly bucket: Bucket; | |
constructor(scope: Construct, id: string, props: StackProps) { | |
super(scope, id, props); | |
this.bucket = new Bucket(this, 'ExportedBucket'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Having defined const api: RestApi | |
const robotsResource = api.root.addResource('robots.txt'); | |
const headMethod = robotsResource.addMethod('HEAD', mockIntegration, methodOptions); | |
const getMethod = robotsResource.addMethod('GET', mockIntegration, methodOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const methodOptions: MethodOptions = { | |
methodResponses: [{ | |
statusCode: '200', | |
responseModels: { | |
'text/plain': Model.EMPTY_MODEL | |
} | |
}] | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mockIntegration = new MockIntegration({ | |
requestTemplates: { | |
'application/json': '{"statusCode": 200}' | |
}, | |
integrationResponses: [{ | |
statusCode: '200', | |
responseTemplates: { | |
'text/plain': | |
`User-agent: * | |
Disallow: / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ISet<string> allowedOrigins; // ["https://my-origin-1.com", "https://my-origin-2.com"] received e.g. from SSM | |
var originHeader = request.headers.FirstOrDefault(x => "Origin".Equals(x.Key, StringComparison.InvariantCultureIgnoreCase)); | |
// Only single allowed origin is possible in the response. Pick it based on the origin of the request | |
var allowedOrigin = allowedOrigins.Contains(originHeader.Value?.ToLower()) ? originHeader.Value : string.Empty; | |
return new // response | |
{ | |
headers = new Dictionary<string, string> | |
{ | |
{ "Access-Control-Allow-Origin", allowedOrigin }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Request | |
{ | |
... | |
"headers": { | |
"header1": "value1", | |
"header2": "value2" | |
}, | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// const origins = ['https://my-origin-1.com', 'https://my-origin-2.com']; | |
const responses: IntegrationResponse[] = [{ | |
statusCode: "200", | |
responseTemplates: { | |
'application/json': getAllowOrigin(origins) + '$input.body' // or other template you need | |
} | |
}/*, ...rest of your responses */]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getAllowOrigin = (origins: string[]) => | |
{ | |
const condition = origins | |
.map(x => `$origin.matches(\"${x}\")`) | |
.reduce((l,r) => `${l} || ${r}`); | |
return `#set($origin = $input.params(\"Origin\"))\n#if($origin == \"\") #set($origin = $input.params(\"origin\")) #end\n#if(${condition})\n #set($context.responseOverride.header.Access-Control-Allow-Origin = $origin)\n#end\n`; | |
} |