Skip to content

Commit

Permalink
Record OpenSearch error logs
Browse files Browse the repository at this point in the history
MCP asked us to do this for compliance purposes.
  • Loading branch information
lpsinger committed Aug 6, 2024
1 parent aab58aa commit 828fa8c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
14 changes: 14 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ async function executeSearchRequests(cwd: string) {
}
}

function addTransforms(
cloudformation: { Transform?: string[] | string },
...transforms: string[]
) {
if (cloudformation.Transform === undefined) {
cloudformation.Transform = transforms
} else if (typeof cloudformation.Transform === 'string') {
cloudformation.Transform = [cloudformation.Transform, ...transforms]
} else {
cloudformation.Transform.push(...transforms)
}
}

export const deploy = {
// @ts-expect-error: The Architect plugins API has no type definitions.
start({ cloudformation, inventory, arc, stage }) {
Expand All @@ -74,6 +87,7 @@ export const deploy = {
resources = serverlessCloudformationResources(collectionName)
}
Object.assign(cloudformation.Resources, resources)
addTransforms(cloudformation, 'AWS::LanguageExtensions')
return cloudformation
},
// @ts-expect-error: The Architect plugins API has no type definitions.
Expand Down
39 changes: 39 additions & 0 deletions service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,37 @@ export function cloudformationResources({
}

return {
OpenSearchLogGroup: {
Type: 'AWS::Logs::LogGroup',
Properties: {
LogGroupName: {
'Fn::Sub': [
'/aws/OpenSearchService/domains/${OpenSearchServiceDomain}',
{ OpenSearchServiceDomain: { Ref: 'OpenSearchServiceDomain' } },
],
},
},
},
OpenSearchLogPolicy: {
Type: 'AWS::Logs::ResourcePolicy',
Properties: {
PolicyName: { 'Fn::Sub': '${AWS::StackName}-OpenSearchLogPolicy' },
PolicyDocument: {
'Fn::ToJsonString': {
Version: '2012-10-17',
Statement: [
{
Sid: '',
Effect: 'Allow',
Principal: { Service: 'es.amazonaws.com' },
Action: ['logs:PutLogEvents', 'logs:CreateLogStream'],
Resource: { 'Fn::GetAtt': ['OpenSearchLogGroup', 'Arn'] },
},
],
},
},
},
},
OpenSearchServiceDomain: {
Type: 'AWS::OpenSearchService::Domain',
Properties: {
Expand Down Expand Up @@ -67,6 +98,14 @@ export function cloudformationResources({
EBSOptions: { EBSEnabled: true, VolumeSize },
EncryptionAtRestOptions: { Enabled: true },
IPAddressType: 'dualstack',
// LogPublishingOptions: {
// ES_APPLICATION_LOGS: {
// CloudWatchLogsLogGroupArn: {
// 'Fn::GetAtt': ['OpenSearchLogGroup', 'Arn'],
// },
// Enabled: true,
// },
// },
NodeToNodeEncryptionOptions: { Enabled: true },
},
},
Expand Down

0 comments on commit 828fa8c

Please sign in to comment.