Skip to content

Commit

Permalink
Merge branch 'main' into add-service-code-to-stub
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherjturner authored Aug 1, 2024
2 parents cc9e870 + 2cfe978 commit 9e01a3a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/api/ecs/deployment-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { config } from '~/src/config'

import { ecsDeploymentEvent } from '~/src/api/ecs/payloads/ecs-deployment-event'
import { lambdaDeploymentUpdate } from '~/src/api/ecs/payloads/lambda-deployment-update'
import { ecsDeployStatusChangeEvent } from '~/src/api/ecs/payloads/ecs-deploy-status-change-event'

const logger = createLogger()

Expand All @@ -22,7 +23,7 @@ async function deploymentHandler(sqs, payload) {
const instanceCount = msg?.desired_count

const deploymentId = msg?.deployed_by?.deployment_id
const lamdaId = crypto.randomUUID()
const lamdaId = `ecs-svc/${crypto.randomUUID()}`
const taskId = Math.floor(Math.random() * 1000000)

// Lamba update
Expand Down Expand Up @@ -62,6 +63,15 @@ async function deploymentHandler(sqs, payload) {
await send(sqs, payload, deploymentFlow[j].delay)
}
}

const deployStatusChangeEvent = ecsDeployStatusChangeEvent(
awsAccount,
new Date(),
lamdaId,
'SERVICE_DEPLOYMENT_COMPLETED',
`ECS deployment ${lamdaId} completed.`
)
await send(sqs, deployStatusChangeEvent, 5)
}

async function send(sqs, payload, delay = 0) {
Expand Down
28 changes: 28 additions & 0 deletions src/api/ecs/payloads/ecs-deploy-status-change-event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function ecsDeployStatusChangeEvent(
awsAccountId,
now,
deploymentId,
eventName,
reason
) {
return {
version: '0',
id: crypto.randomUUID(),
'detail-type': 'ECS Deployment State Change',
source: 'aws.ecs',
account: awsAccountId,
time: now,
region: 'eu-west-2',
resources: [
`arn:aws:ecs:eu-west-2:${awsAccountId}:task/dev-ecs-public/f8bec92bed774ee4b27711702a862de5`
],
detail: {
eventType: 'INFO',
eventName,
deploymentId,
updatedAt: now,
reason
}
}
}
export { ecsDeployStatusChangeEvent }
2 changes: 1 addition & 1 deletion src/api/ecs/payloads/ecs-deployment-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function ecsDeploymentEvent(
pullStartedAt: now,
pullStoppedAt: now,
startedAt: now,
startedBy: `ecs-svc/${lambdaId}`,
startedBy: lambdaId,
taskArn: `arn:aws:ecs:eu-west-2:000000000000:task/dev-ecs-public/${taskArn}`,
taskDefinitionArn: `arn:aws:ecs:eu-west-2:000000000000:task-definition/${service}:${taskId}`,
updatedAt: now,
Expand Down
2 changes: 1 addition & 1 deletion src/api/ecs/payloads/lambda-deployment-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function lambdaDeploymentUpdate(
detail: {
eventType: 'INFO',
eventName: 'IN_PROGRESS',
deploymentId: `ecs-svc/${lambdaId}`,
deploymentId: lambdaId,
reason: `Deployment arn:aws:ecs:eu-west-2:${awsAccountId}:service/infra-dev-ecs-public/${service} successfully updated`
},
deployed_by: 'Test, User',
Expand Down

0 comments on commit 9e01a3a

Please sign in to comment.