Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Basic set up for three package managers
version: 2
updates:

# Maintain dependencies for npm
- package-ecosystem: "npm"
# https://github.com/dependabot/dependabot-core/issues/1778
target-branch: main
groups:
npm:
patterns:
- '*'
directory: "/"
schedule:
interval: "weekly"
registries:
- npm-npmjs
ignore:
# Covered below
- dependency-name: '@mapbox/mapbox-cdk-common'

# Make sure the mapbox-cdk-common package stands out
- package-ecosystem: "npm"
allow:
- dependency-name: '@mapbox/mapbox-cdk-common'
groups:
mapbox-cdk-common:
patterns:
- '*'
directory: "/"
schedule:
interval: "daily"
registries:
- npm-npmjs

registries:
npm-npmjs:
type: npm-registry
url: https://registry.npmjs.org
token: ${{ secrets.NPM_TOKEN_READONLY }}
replaces-base: true
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@ jobs:
contents: read
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: '3.7.17'

- name: pip install
run: |
pip install -r requirements.dev.txt

- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- run: |
npm ci

- run: |
npm run test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ cloudformation/*.json
node_modules
.python-version
.vscode
*.tgz
5 changes: 4 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
venv
*
!index.js
!lib/**
!bin/**
18 changes: 18 additions & 0 deletions lib/shortcuts/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ Log Group, a Role, an Alarm on function errors, and the Lambda Function itself.<
Includes a Log Group, a Role, an Alarm on function errors, a CloudWatch Subscription Filter,
and a Lambda permission.</p>
</dd>
<dt><a href="#MapboxDnsRecordAlias">MapboxDnsRecordAlias</a></dt>
<dd><p>Create an ALIAS DNS record in mapbox.com/tilestream.net/mbxinternal.com</p>
</dd>
<dt><a href="#QueueLambda">QueueLambda</a></dt>
<dd><p>A Lambda function that runs in response to messages in an SQS queue.
Includes a Log Group, a Role, an Alarm on function errors, and an event source
Expand Down Expand Up @@ -475,6 +478,21 @@ const lambda = new cf.shortcuts.LogSubscriptionLambda({

module.exports = cf.merge(myTemplate, lambda);
```
<a name="MapboxDnsRecordAlias"></a>

## MapboxDnsRecordAlias
Create an ALIAS DNS record in mapbox.com/tilestream.net/mbxinternal.com

**Kind**: global class
<a name="new_MapboxDnsRecordAlias_new"></a>

### new MapboxDnsRecordAlias(options)

| Param | Type | Description |
| --- | --- | --- |
| options | <code>Object</code> | Options. |
| options.LogicalName | <code>String</code> | The logical name of the IAM role within the CloudFormation template. const cf = require('@mapbox/cloudfriend'); const myTemplate = { ... }; const record = new cf.shortcuts.MapboxDnsRecordAlias({ Id: 'My-Record', // This becomes part of the logical id of the output Name: 'record-1', // Becomes 'record-1.mapbox.com' Environment: 'staging', HostedZone: 'mapbox.com', // Or 'tilestream.net' or 'mbxinternal.com', Routing: 'Simple', // Or 'Weighted', 'Latency', 'Geo' Target: LoadBalancerLogicalId, HealthChecks: [{ Path: '/lite' }], }); module.exports = cf.merge(myTemplate, record); |

<a name="QueueLambda"></a>

## QueueLambda
Expand Down
4 changes: 3 additions & 1 deletion lib/shortcuts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ module.exports = {
GluePrestoView: require('./glue-presto-view'),
GlueSparkView: require('./glue-spark-view'),
hookshot: require('./hookshot'),
LogSubscriptionLambda: require('./log-subscription-lambda')
LogSubscriptionLambda: require('./log-subscription-lambda'),
MapboxDnsRecordAlias: require('./mapbox-dns-record-alias'),
MapboxDnsRecordNonAlias: require('./mapbox-dns-record-non-alias')
};
64 changes: 64 additions & 0 deletions lib/shortcuts/mapbox-dns-record-alias.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use strict';
const Joi = require('joi');

const intrinsic = require('../intrinsic');
const cdkCommonDNS = require('@mapbox/mapbox-cdk-common/lib/constructs/mapbox-dns-record');
const cdkCommonSchemaDNS = require('@mapbox/mapbox-cdk-common/lib/utils/schemas/dns-schema');

/**
* Create an ALIAS DNS record in mapbox.com/tilestream.net/mbxinternal.com
*
* @param {Object} options - Options.
* @param {String} options.LogicalName - The logical name of the IAM role
* within the CloudFormation template.
*
* const cf = require('@mapbox/cloudfriend');
*
* const myTemplate = { ... };
*
* const record = new cf.shortcuts.MapboxDnsRecordAlias({
* Id: 'My-Record', // This becomes part of the logical id of the output
* Name: 'record-1', // Becomes 'record-1.mapbox.com'
* Environment: 'staging',
* HostedZone: 'mapbox.com', // Or 'tilestream.net' or 'mbxinternal.com',
* Routing: 'Simple', // Or 'Weighted', 'Latency', 'Geo'
* Target: LoadBalancerLogicalId,
* HealthChecks: [{ Path: '/lite' }],
* });
*
* module.exports = cf.merge(myTemplate, record);
*/
class MapboxDnsRecordAlias {
constructor(options) {
if (!options) throw new Error('Options required');

const {
Id,
HostedZone,
Target,
...rest
} = options;

const foundHostedZone = Object.values(cdkCommonSchemaDNS.MapboxHostedZones).find((z) => z.HostedZoneName === HostedZone);
if (!foundHostedZone) {
throw new Error(`Invalid HostedZone parameter. Must be one of: ${Object.values(cdkCommonSchemaDNS.MapboxHostedZones).map((v) => v.HostedZoneName).join(', ')}`);
}

const loadBalancerCanonicalHostedZoneId = intrinsic.getAtt(Target, 'CanonicalHostedZoneID');
const loadBalancerDnsName = intrinsic.getAtt(Target, 'DNSName');

const dnsRecordProps = {
...rest,
HostedZone: foundHostedZone,
Target: {
loadBalancerCanonicalHostedZoneId,
loadBalancerDnsName
}
};

this.Transform = 'AWS::LanguageExtensions';
this.Outputs = new cdkCommonDNS.MapboxDnsRecordAlias(dnsRecordProps).toCloudfriendOutputs(Id);
}
}

module.exports = MapboxDnsRecordAlias;
56 changes: 56 additions & 0 deletions lib/shortcuts/mapbox-dns-record-non-alias.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use strict';

const cdkCommonDNS = require('@mapbox/mapbox-cdk-common/lib/constructs/mapbox-dns-record');
const cdkCommonSchemaDNS = require('@mapbox/mapbox-cdk-common/lib/utils/schemas/dns-schema');
const Joi = require('joi');

/**
* Create a DNS record in mapbox.com/tilestream.net/mbxinternal.com
*
* @param {Object} options - Options.
* @param {String} options.LogicalName - The logical name of the IAM role
* within the CloudFormation template.
*
* const cf = require('@mapbox/cloudfriend');
*
* const myTemplate = { ... };
*
* const record = new cf.shortcuts.MapboxDnsRecordNonAlias({
* Id: 'My-Record', // This becomes part of the logical id of the output
* Name: 'record-1', // Becomes 'record-1.mapbox.com'
* Environment: 'staging',
* HostedZone: 'mapbox.com', // Or 'tilestream.net' or 'mbxinternal.com',
* Routing: 'Simple', // Or 'Weighted', 'Latency', 'Geo'
* Target: 'hello.com',
* HealthChecks: [{ FQDN: 'mydomain.com', Path: '/lite' }],
* Type: 'A', // Or, 'CNAME', 'AAAA'
* TTL: 10, // Seconds
* });
*
* module.exports = cf.merge(myTemplate, record);
*/
class MapboxDnsRecordNonAlias {
constructor(options) {
if (!options) throw new Error('Options required');

const {
Id,
HostedZone,
...rest
} = options;

const foundHostedZone = Object.values(cdkCommonSchemaDNS.MapboxHostedZones).find((z) => z.HostedZoneName === HostedZone);
if (!foundHostedZone) {
throw new Error(`Invalid HostedZone parameter. Must be one of: ${Object.values(cdkCommonSchemaDNS.MapboxHostedZones).map((v) => v.HostedZoneName).join(', ')}`);
}

const dnsRecordProps = {
...rest,
HostedZone: foundHostedZone
};

this.Outputs = new cdkCommonDNS.MapboxDnsRecordNonAlias(dnsRecordProps).toCloudfriendOutputs(Id);
}
}

module.exports = MapboxDnsRecordNonAlias;
Loading
Loading