aws-sdk#Route53 TypeScript Examples
The following examples show how to use
aws-sdk#Route53.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: handlers.ts From aws-resource-providers with MIT License | 6 votes |
private async createVpcAssociation(action: Action, service: Route53, logger: Logger, model: ResourceModel): Promise<ResourceModel> {
const request: Route53.AssociateVPCWithHostedZoneRequest = {
HostedZoneId: model.hostedZoneId,
VPC: {
VPCId: model.vPC.vPCId,
VPCRegion: model.vPC.vPCRegion,
},
};
logger.log({ action, message: 'before invoke associateVPCWithHostedZone', request });
const response = await service.associateVPCWithHostedZone(request).promise();
logger.log({ action, message: 'after invoke associateVPCWithHostedZone', response });
logger.log({ action, message: 'done', model });
model.resourceId = `${model.hostedZoneId}/${model.vPC.vPCRegion}/${model.vPC.vPCId}`;
return model;
}
Example #2
Source File: handlers.ts From aws-resource-providers with MIT License | 6 votes |
private async deleteVpcAssociation(action: Action, service: Route53, logger: Logger, model: ResourceModel): Promise<null> {
const request: Route53.DisassociateVPCFromHostedZoneRequest = {
HostedZoneId: model.hostedZoneId,
VPC: {
VPCId: model.vPC.vPCId,
VPCRegion: model.vPC.vPCRegion,
},
};
logger.log({ action, message: 'before invoke disassociateVPCFromHostedZone', request });
const response = await service.disassociateVPCFromHostedZone(request).promise();
logger.log({ action, message: 'after invoke disassociateVPCFromHostedZone', response });
logger.log({ action, message: 'done', model });
return null;
}
Example #3
Source File: handlers.ts From aws-resource-providers with MIT License | 6 votes |
private async createVpcAssociationAuthorization(action: Action, service: Route53, logger: Logger, model: ResourceModel): Promise<ResourceModel> {
const request: Route53.CreateVPCAssociationAuthorizationRequest = {
HostedZoneId: model.hostedZoneId,
VPC: {
VPCId: model.vPC.vPCId,
VPCRegion: model.vPC.vPCRegion,
},
};
logger.log({ action, message: 'before invoke createVPCAssociationAuthorization', request });
const response = await service.createVPCAssociationAuthorization(request).promise();
logger.log({ action, message: 'after invoke createVPCAssociationAuthorization', response });
logger.log({ action, message: 'done', model });
model.resourceId = `${model.hostedZoneId}/${model.vPC.vPCRegion}/${model.vPC.vPCId}`;
return model;
}
Example #4
Source File: handlers.ts From aws-resource-providers with MIT License | 6 votes |
private async deleteVpcAssociationAuthorization(action: Action, service: Route53, logger: Logger, model: ResourceModel): Promise<null> {
const request: Route53.DeleteVPCAssociationAuthorizationRequest = {
HostedZoneId: model.hostedZoneId,
VPC: {
VPCId: model.vPC.vPCId,
VPCRegion: model.vPC.vPCRegion,
},
};
logger.log({ action, message: 'before invoke deleteVPCAssociationAuthorization', request });
const response = await service.deleteVPCAssociationAuthorization(request).promise();
logger.log({ action, message: 'after invoke deleteVPCAssociationAuthorization', response });
logger.log({ action, message: 'done', model });
return null;
}
Example #5
Source File: handlers.ts From aws-resource-providers with MIT License | 6 votes |
private async listVPCAssociationAuthorizations(action: Action, service: Route53, logger: Logger, model: ResourceModel): Promise<Route53.VPC[]> {
const request: Route53.ListVPCAssociationAuthorizationsRequest = { HostedZoneId: model.hostedZoneId };
logger.log({ action, message: 'before invoke createVPCAssociationAuthorization', request });
let vpcs: Array<Route53.VPC> = [];
let response = await service.listVPCAssociationAuthorizations(request).promise();
vpcs = vpcs.concat(response.VPCs);
logger.log({ action, message: 'after invoke createVPCAssociationAuthorization', response });
logger.log({ action, message: 'done', model });
while (response.NextToken) {
logger.log({ action, message: 'before invoke createVPCAssociationAuthorization', request });
response = await service.listVPCAssociationAuthorizations(request).promise();
vpcs = vpcs.concat(response.VPCs);
logger.log({ action, message: 'after invoke createVPCAssociationAuthorization', response });
logger.log({ action, message: 'done', model });
}
return vpcs;
}
Example #6
Source File: handlers.ts From aws-resource-providers with MIT License | 6 votes |
@handlerEvent(Action.Read)
@commonAws({ serviceName: 'Route53', debug: true })
public async read(action: Action, args: HandlerArgs<ResourceModel>, service: Route53, model: ResourceModel): Promise<ResourceModel> {
const [hostedZoneId, vpcRegion, vpcId] = model.resourceId.split('/');
const vpcs = await this.listVPCAssociationAuthorizations(action, service, args.logger, model);
const targetVpc = vpcs.find((vpc) => vpc.VPCId === vpcId && vpc.VPCRegion === vpcRegion);
if (!targetVpc) throw new exceptions.NotFound(this.typeName, model.resourceId);
model.hostedZoneId = hostedZoneId;
model.vPC = VPC.deserialize({
vPCRegion: vpcRegion,
vPCId: vpcId,
});
return model;
}
Example #7
Source File: handlers.test.ts From aws-resource-providers with MIT License | 5 votes |
describe('when calling handler', () => {
let testEntrypointPayload: any;
let spySession: jest.SpyInstance;
let spySessionClient: jest.SpyInstance;
let route53: AwsServiceMockBuilder<Route53>;
let fixtureMap: Map<Action, Record<string, any>>;
beforeAll(() => {
fixtureMap = new Map<Action, Record<string, any>>();
fixtureMap.set(Action.Create, createFixture);
fixtureMap.set(Action.Update, updateFixture);
fixtureMap.set(Action.Delete, deleteFixture);
});
beforeEach(async () => {
route53 = on(Route53, { snapshot: false });
route53.mock('associateVPCWithHostedZone').resolve({
ChangeInfo: {
Id: 'someId',
Status: 'PENDING',
SubmittedAt: new Date(),
Comment: '',
},
});
route53.mock('disassociateVPCFromHostedZone').resolve({
ChangeInfo: {
Id: 'someId',
Status: 'PENDING',
SubmittedAt: new Date(),
Comment: '',
},
});
spySession = jest.spyOn(SessionProxy, 'getSession');
spySessionClient = jest.spyOn<any, any>(SessionProxy.prototype, 'client');
spySessionClient.mockReturnValue(route53.instance);
testEntrypointPayload = {
credentials: { accessKeyId: '', secretAccessKey: '', sessionToken: '' },
region: 'us-east-1',
};
});
afterEach(() => {
jest.clearAllMocks();
jest.restoreAllMocks();
});
test('create operation successful - vpc association', async () => {
const request = fixtureMap.get(Action.Create);
const progress = await resource.testEntrypoint({ ...testEntrypointPayload, action: Action.Create, request }, null);
expect(progress).toMatchObject({ status: OperationStatus.Success, message: '', callbackDelaySeconds: 0 });
expect(progress.resourceModel.serialize()).toMatchObject({ ...request.desiredResourceState, ResourceId: 'Z123456789012345678/us-east-1/v-12345678901234567' });
});
test('update operation successful - vpc association', async () => {
const request = fixtureMap.get(Action.Update);
const progress = await resource.testEntrypoint({ ...testEntrypointPayload, action: Action.Update, request }, null);
expect(progress).toMatchObject({ status: OperationStatus.Success, message: '', callbackDelaySeconds: 0 });
expect(progress.resourceModel.serialize()).toMatchObject(request.desiredResourceState);
});
test('delete operation successful - vpc association', async () => {
const request = fixtureMap.get(Action.Delete);
const progress = await resource.testEntrypoint({ ...testEntrypointPayload, action: Action.Delete, request }, null);
expect(progress).toMatchObject({ status: OperationStatus.Success, message: '', callbackDelaySeconds: 0 });
expect(progress.resourceModel).toBeNull();
});
test('all operations fail without session - vpc association', async () => {
expect.assertions(fixtureMap.size);
spySession.mockReturnValue(null);
for (const [action, request] of fixtureMap) {
const progress = await resource.testEntrypoint({ ...testEntrypointPayload, action, request }, null);
console.log(JSON.stringify(progress));
expect(progress.errorCode).toBe(exceptions.InvalidCredentials.name);
}
});
});
Example #8
Source File: handlers.ts From aws-resource-providers with MIT License | 5 votes |
@handlerEvent(Action.Create)
@commonAws({ serviceName: 'Route53', debug: true })
public async create(action: Action, args: HandlerArgs<ResourceModel>, service: Route53, model: ResourceModel): Promise<ResourceModel> {
if (model.resourceId) throw new exceptions.InvalidRequest('Read only property [ResourceId] cannot be provided by the user.');
return this.createVpcAssociation(action, service, args.logger, model);
}
Example #9
Source File: handlers.ts From aws-resource-providers with MIT License | 5 votes |
@handlerEvent(Action.Update)
@commonAws({ serviceName: 'Route53', debug: true })
public async update(action: Action, args: HandlerArgs<ResourceModel>, service: Route53, model: ResourceModel): Promise<ResourceModel> {
if (model.resourceId) throw new exceptions.InvalidRequest('Read only property [ResourceId] cannot be provided by the user.');
return this.createVpcAssociation(action, service, args.logger, model);
}
Example #10
Source File: handlers.ts From aws-resource-providers with MIT License | 5 votes |
@handlerEvent(Action.Delete)
@commonAws({ serviceName: 'Route53', debug: true })
public async delete(action: Action, args: HandlerArgs<ResourceModel>, service: Route53, model: ResourceModel): Promise<null> {
return this.deleteVpcAssociation(action, service, args.logger, model);
}
Example #11
Source File: handlers.test.ts From aws-resource-providers with MIT License | 5 votes |
describe('when calling handler', () => {
let testEntrypointPayload: any;
let spySession: jest.SpyInstance;
let spySessionClient: jest.SpyInstance;
let route53: AwsServiceMockBuilder<Route53>;
let fixtureMap: Map<Action, Record<string, any>>;
beforeAll(() => {
fixtureMap = new Map<Action, Record<string, any>>();
fixtureMap.set(Action.Create, createFixture);
fixtureMap.set(Action.Update, updateFixture);
fixtureMap.set(Action.Delete, deleteFixture);
});
beforeEach(async () => {
route53 = on(Route53, { snapshot: false });
route53.mock('createVPCAssociationAuthorization').resolve({
HostedZoneId: 'Z123456789012345678',
VPC: {
VPCRegion: 'us-east-1',
VPCId: 'v-12345678901234567',
},
});
route53.mock('deleteVPCAssociationAuthorization').resolve({});
route53.mock('listVPCAssociationAuthorizations').resolve({
VPCs: [
{
VPCRegion: 'us-east-1',
VPCId: 'v-12345678901234567',
},
],
});
spySession = jest.spyOn(SessionProxy, 'getSession');
spySessionClient = jest.spyOn<any, any>(SessionProxy.prototype, 'client');
spySessionClient.mockReturnValue(route53.instance);
testEntrypointPayload = {
credentials: { accessKeyId: '', secretAccessKey: '', sessionToken: '' },
region: 'us-east-1',
};
});
afterEach(() => {
jest.clearAllMocks();
jest.restoreAllMocks();
});
test('create operation successful - vpc association', async () => {
const request = fixtureMap.get(Action.Create);
const progress = await resource.testEntrypoint({ ...testEntrypointPayload, action: Action.Create, request }, null);
expect(progress).toMatchObject({ status: OperationStatus.Success, message: '', callbackDelaySeconds: 0 });
expect(progress.resourceModel.serialize()).toMatchObject({ ...request.desiredResourceState, ResourceId: 'Z123456789012345678/us-east-1/v-12345678901234567' });
});
test('update operation successful - vpc association', async () => {
const request = fixtureMap.get(Action.Update);
const progress = await resource.testEntrypoint({ ...testEntrypointPayload, action: Action.Update, request }, null);
expect(progress).toMatchObject({ status: OperationStatus.Success, message: '', callbackDelaySeconds: 0 });
expect(progress.resourceModel.serialize()).toMatchObject(request.desiredResourceState);
});
test('delete operation successful - vpc association', async () => {
const request = fixtureMap.get(Action.Delete);
const progress = await resource.testEntrypoint({ ...testEntrypointPayload, action: Action.Delete, request }, null);
expect(progress).toMatchObject({ status: OperationStatus.Success, message: '', callbackDelaySeconds: 0 });
expect(progress.resourceModel).toBeNull();
});
test('all operations fail without session - vpc association', async () => {
expect.assertions(fixtureMap.size);
spySession.mockReturnValue(null);
for (const [action, request] of fixtureMap) {
const progress = await resource.testEntrypoint({ ...testEntrypointPayload, action, request }, null);
console.log(JSON.stringify(progress));
expect(progress.errorCode).toBe(exceptions.InvalidCredentials.name);
}
});
});
Example #12
Source File: handlers.ts From aws-resource-providers with MIT License | 5 votes |
@handlerEvent(Action.Create)
@commonAws({ serviceName: 'Route53', debug: true })
public async create(action: Action, args: HandlerArgs<ResourceModel>, service: Route53, model: ResourceModel): Promise<ResourceModel> {
if (model.resourceId) throw new exceptions.InvalidRequest('Read only property [ResourceId] cannot be provided by the user.');
return this.createVpcAssociationAuthorization(action, service, args.logger, model);
}
Example #13
Source File: handlers.ts From aws-resource-providers with MIT License | 5 votes |
@handlerEvent(Action.Update)
@commonAws({ serviceName: 'Route53', debug: true })
public async update(action: Action, args: HandlerArgs<ResourceModel>, service: Route53, model: ResourceModel): Promise<ResourceModel> {
if (model.resourceId) throw new exceptions.InvalidRequest('Read only property [ResourceId] cannot be provided by the user.');
return this.createVpcAssociationAuthorization(action, service, args.logger, model);
}
Example #14
Source File: handlers.ts From aws-resource-providers with MIT License | 5 votes |
@handlerEvent(Action.Delete)
@commonAws({ serviceName: 'Route53', debug: true })
public async delete(action: Action, args: HandlerArgs<ResourceModel>, service: Route53, model: ResourceModel): Promise<null> {
return this.deleteVpcAssociationAuthorization(action, service, args.logger, model);
}