Skip to content

Commit

Permalink
build(deps-dev): bump dependencies (#119)
Browse files Browse the repository at this point in the history
* build(deps-dev): bump jsii and aws-cdk-lib

* build(deps-dev): bump commitlint, semantic-release, and eslint

* build(deps-dev): bump aws-sdk, aws-xray-sdk-core, and aws-lambda

* build(deps-dev): bump jest, node

* chore: update package-lock.json
  • Loading branch information
engineal authored May 1, 2023
1 parent 628d93b commit 6b3b3b0
Show file tree
Hide file tree
Showing 5 changed files with 10,568 additions and 17,447 deletions.
32 changes: 18 additions & 14 deletions lib/ecs-public-discovery.function.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* eslint-disable no-console,no-process-env */
import * as AWS from 'aws-sdk';
import * as AWSXRay from 'aws-xray-sdk-core';
import {EC2, NetworkInterface, Tag} from '@aws-sdk/client-ec2';
import {ResourceRecordSet, Route53} from '@aws-sdk/client-route-53';
import {EventBridgeHandler} from 'aws-lambda';
import {Task} from '@aws-sdk/client-ecs';

const ec2Client = AWSXRay.captureAWSClient(new AWS.EC2());
const route53Client = AWSXRay.captureAWSClient(new AWS.Route53());
const ec2Client = AWSXRay.captureAWSv3Client(new EC2({}));
const route53Client = AWSXRay.captureAWSv3Client(new Route53({}));

const DEFAULT_TTL = 60;

Expand All @@ -20,7 +22,7 @@ if (!hostedZoneName) {
throw new Error('HOSTED_ZONE_NAME environment variable is not set!');
}

const getNetworkInterfaceForTask = async (task: AWS.ECS.Task, taskId: string): Promise<AWS.EC2.NetworkInterface> => {
const getNetworkInterfaceForTask = async (task: Task, taskId: string): Promise<NetworkInterface> => {
const networkInterfaceId = task.attachments
?.find(attachment => attachment.type === 'eni')?.details
?.find(details => details.name === 'networkInterfaceId')?.value;
Expand All @@ -30,7 +32,7 @@ const getNetworkInterfaceForTask = async (task: AWS.ECS.Task, taskId: string): P
}
const networkInterfacesResponse = await ec2Client.describeNetworkInterfaces({
NetworkInterfaceIds: [networkInterfaceId]
}).promise();
});

if (!networkInterfacesResponse.NetworkInterfaces) {
throw new Error('DescribeNetworkInterfaces did not return any network interfaces!');
Expand All @@ -40,9 +42,9 @@ const getNetworkInterfaceForTask = async (task: AWS.ECS.Task, taskId: string): P
return networkInterfacesResponse.NetworkInterfaces[0];
};

const getTag = (key: string, tags?: AWS.EC2.TagList): string | undefined => tags?.find(tag => tag.Key === key)?.Value;
const getTag = (key: string, tags?: Tag[]): string | undefined => tags?.find(tag => tag.Key === key)?.Value;

const getRequiredTag = (key: string, error: string, tags?: AWS.EC2.TagList): string => {
const getRequiredTag = (key: string, error: string, tags?: Tag[]): string => {
const tag = getTag(key, tags);

if (!tag) {
Expand All @@ -52,7 +54,7 @@ const getRequiredTag = (key: string, error: string, tags?: AWS.EC2.TagList): str
return tag;
};

const handleTaskRunning = async (taskId: string, networkInterface: AWS.EC2.NetworkInterface) => {
const handleTaskRunning = async (taskId: string, networkInterface: NetworkInterface) => {
const nameTag = getRequiredTag(
'public-discovery:name',
`Task ${taskId} does not have the 'public-discovery:name' tag.`,
Expand Down Expand Up @@ -85,7 +87,7 @@ const handleTaskRunning = async (taskId: string, networkInterface: AWS.EC2.Netwo
}]
},
HostedZoneId: hostedZoneId
}).promise();
});
};

const getResourceRecordSetByIdentifier = async (
Expand All @@ -94,15 +96,17 @@ const getResourceRecordSetByIdentifier = async (
startRecordName?: string,
startRecordType?: string
// eslint-disable-next-line max-params
): Promise<AWS.Route53.ResourceRecordSet | undefined> => {
): Promise<ResourceRecordSet | undefined> => {
// eslint-disable-next-line no-warning-comments
// TODO: replace with paginate when added to AWS SDK
const resourceRecordSetsResponse = await route53Client.listResourceRecordSets({
HostedZoneId: hostedZoneId,
StartRecordIdentifier: startRecordIdentifier,
StartRecordName: startRecordName,
StartRecordType: startRecordType
}).promise();
});

const resourceRecordSet = resourceRecordSetsResponse.ResourceRecordSets.find(rrs => rrs.MultiValueAnswer &&
const resourceRecordSet = resourceRecordSetsResponse.ResourceRecordSets?.find(rrs => rrs.MultiValueAnswer &&
rrs.Type === 'A' && rrs.SetIdentifier === setIdentifier);

if (resourceRecordSet) {
Expand Down Expand Up @@ -151,10 +155,10 @@ const handleTaskStopped = async (taskId: string) => {
}]
},
HostedZoneId: hostedZoneId
}).promise();
});
};

export const handler: EventBridgeHandler<'ECS Task State Change', AWS.ECS.Task, void> = async event => {
export const handler: EventBridgeHandler<'ECS Task State Change', Task, void> = async event => {
const {taskArn} = event.detail;

if (!taskArn) {
Expand Down
Loading

0 comments on commit 6b3b3b0

Please sign in to comment.