- CrossAccountRole
Create an IAM role that will be assumed from another AWS Account.
- EventLambda
A Lambda function that runs in reaction to a CloudWatch Event. Includes a LogGroup, a Role, an Alarm on function errors, a CloudWatch Event Rule, and a Lambda permission.
- GlueDatabase
Create a Glue Database.
- GlueJsonTable
Create a Glue Table backed by line-delimited JSON files on S3.
- GlueOrcTable
Create a Glue Table backed by ORC files on S3.
- GlueParquetTable
Create a Glue table backed by Parquet files on S3.
- GluePrestoView
Create a Glue Presto View.
- GlueSparkView
Create a Glue Presto View.
- GlueTable
Create a Glue Table.
Pre-configured versions of this shortcut are available for tables stored as line-delimited JSON or ORC:
- KinesisFirehoseBase
Base class for creating a Kinesis Firehouse that can receive records by direct put or by consuming a Kinesis Stream. Each implementing subclass enables writing to a specific destination. Creates a Kinesis Firehouse delivery stream, sets up logging and creates a policy allowing records to be delivered to the delivery stream.
- Lambda
Baseline CloudFormation resources involved in a Lambda Function. Creates a Log Group, a Role, an Alarm on function errors, and the Lambda Function itself.
- LogSubscriptionLambda
A Lambda function that runs in response to a log subscription filter. Includes a Log Group, a Role, an Alarm on function errors, a CloudWatch Subscription Filter, and a Lambda permission.
- QueueLambda
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 mapping.
- Queue
Creates an SQS queue with an attached dead-letter queue.
Standard (non-FIFO) queues can receive messages through an SNS topic. The shortcut either creates a new SNS topic that can be used for sending messages into the queue, or subscribes the queue to an existing SNS topic provided with the
ExistingTopicArn
option. For FIFO queues, no SNS topic is created andExistingTopicArn
is ignored.- Role
Create an IAM role.
- S3KinesisFirehose
Creates a Kinesis Firehouse that can receive records by direct put or by consuming a Kinesis Stream and writes out to the specific S3 destination. Creates a Kinesis Firehouse delivery stream, sets up logging, and creates a policy allowing records to be delivered to the delivery stream. Also creates a CloudWatch alarm on the
DeliveryToS3.DataFreshness
metric -- the age of the oldest record in Kinesis Data Firehose (from entering the Kinesis Data Firehose until now). By default, if that metric exceeds double theBufferingIntervalInSeconds
, the alarm is triggered.- ScheduledLambda
A Lambda function that runs on in response to a CloudWatch Event. Includes a Log Group, a Role, an Alarm on function errors, a CloudWatch Event Rule, and a Lambda permission.
- ServiceRole
Create an IAM role that will be assumed by an AWS service, e.g. Lambda or ECS.
- StreamLambda
A Lambda function that runs in response to events in a DynamoDB or Kinesis stream. Includes a Log Group, a Role, an Alarm on function errors, and an event source mapping.
Create an IAM role that will be assumed from another AWS Account.
Param | Type | Description |
---|---|---|
options | Object |
Extends the options for Role . You do not need to provide an AssumeRolePrincipals attribute, but do need to include the following additional attributes: |
options.Accounts | Array.<(String|Object)> |
An array of accounts that can assume this IAM Role. These could be account IDs (123456789012 ), account ARNs (arn:aws:iam::123456789012:root ), or CloudFormation intrinsic function objects (cf.sub('arn:aws:iam::${AccountIdParameter}:root') ). |
Example
const cf = require('@mapbox/cloudfriend');
const myTemplate = { ... };
const role = new cf.shortcuts.CrossAccountRole({
LogicalName: 'MyRole',
Accounts: ['123456789012'],
Statement: [
{
Effect: 'Allow',
Action: 's3:GetObject',
Resource: 'arn:aws:s3:::my-bucket/my/data.tar.gz'
}
]
});
module.exports = cf.merge(myTemplate, role);
A Lambda function that runs in reaction to a CloudWatch Event. Includes a LogGroup, a Role, an Alarm on function errors, a CloudWatch Event Rule, and a Lambda permission.
Param | Type | Default | Description |
---|---|---|---|
options | Object |
Extends the options for Lambda with the following additional attributes: |
|
options.EventPattern | String |
See AWS documentation. | |
[options.State] | String |
'ENABLED' |
See AWS documentation. |
Example
const cf = require('@mapbox/cloudfriend');
const myTemplate = { ... };
const lambda = new cf.shortcuts.EventLambda({
LogicalName: 'MyLambda',
Code: {
S3Bucket: 'my-code-bucket',
S3Key: 'path/to/code.zip'
},
EventPattern: {
'detail-type': ['AWS Console Sign In via CloudTrail'],
detail: {
eventSource: ['signin.amazonaws.com'],
eventName: ['ConsoleLogin']
}
}
});
module.exports = cf.merge(myTemplate, lambda);
Create a Glue Database.
Param | Type | Default | Description |
---|---|---|---|
options | Object |
Options. | |
options.LogicalName | String |
The logical name of the Glue Database within the CloudFormation template. | |
options.Name | String |
The name of the database. See AWS documentation. | |
[options.CatalogId] | String |
AccountId |
The AWS account ID for the account in which to create the database. See AWS documentation. |
[options.Description] | String |
'Created by the ${AWS::StackName} CloudFormation stack' |
The description of the database. See AWS documentation. |
[options.LocationUri] | String |
The location of the database. See AWS documentation. | |
[options.Parameters] | String |
Parameters of the database. See AWS documentation. | |
[options.Condition] | String |
If there is a Condition defined in the template that should control whether to create this database, specify the name of the condition here. See AWS documentation. |
|
[options.DependsOn] | String |
Specify a stack resource dependency to this database. See AWS documentation. |
Example
const cf = require('@mapbox/cloudfriend');
const myTemplate = { ... };
const db = new cf.shortcuts.GlueDatabase({
LogicalName: 'MyDatabase',
Name: 'my_database'
});
module.exports = cf.merge(myTemplate, db);
Create a Glue Table backed by line-delimited JSON files on S3.
Param | Type | Default | Description |
---|---|---|---|
options | Object |
Accepts the same options as GlueTable , though the following additional attributes are either required or hard-wired: |
|
options.Location | String |
The physical location of the table. See AWS documentation. | |
[options.TableType] | String |
'EXTERNAL_TABLE' |
Hard-wired by this shortcut. |
[options.InputFormat] | String |
'org.apache.hadoop.mapred.TextInputFormat' |
Hard-wired by this shortcut. |
[options.OutputFormat] | String |
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' |
Hard-wired by this shortcut. |
[options.SerdeInfo] | Object |
Hard-wired by this shortcut. | |
[options.SerdeInfo.SerializationLibrary] | Object |
'org.openx.data.jsonserde.JsonSerDe' |
Hard-wired by this shortcut. |
Create a Glue Table backed by ORC files on S3.
Param | Type | Default | Description |
---|---|---|---|
options | Object |
Accepts the same options as GlueTable , though the following additional attributes are either required or hard-wired: |
|
options.Location | String |
The physical location of the table. See AWS documentation. | |
[options.TableType] | String |
'EXTERNAL_TABLE' |
Hard-wired by this shortcut. |
[options.InputFormat] | String |
'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat' |
Hard-wired by this shortcut. |
[options.OutputFormat] | String |
'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat' |
Hard-wired by this shortcut. |
[options.SerdeInfo] | Object |
Hard-wired by this shortcut. | |
[options.SerdeInfo.SerializationLibrary] | Object |
'org.apache.hadoop.hive.ql.io.orc.OrcSerde' |
Hard-wired by this shortcut. |
Create a Glue table backed by Parquet files on S3.
Param | Type | Default | Description |
---|---|---|---|
options | Object |
Accepts the same options as cloudfriend's GlueTable , though the following additional attributes are either required or hard-wired: |
|
options.Location | String |
The physical location of the table. See AWS documentation. | |
[options.TableType] | String |
'EXTERNAL_TABLE' |
Hard-wired by this shortcut. |
[options.InputFormat] | String |
'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat' |
- Hard-wired by this shortcut. |
[options.OutputFormat] | String |
'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat' |
- Hard-wired by this shortcut. |
[options.SerdeInfo] | Object |
Hard-wired by this shortcut. | |
[options.SerdeInfo.SerializationLibrary] | String |
'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe' |
- Hard-wired by this shortcut. |
Create a Glue Presto View.
Param | Type | Default | Description |
---|---|---|---|
options | Object |
Accepts the same options as GlueTable , though the following additional attributes are either required or hard-wired: |
|
options.OriginalSql | String |
The SQL query that defines the view. | |
[options.TableType] | String |
'VIRTUAL_VIEW' |
Hard-wired by this shortcut. |
Create a Glue Presto View.
Param | Type | Default | Description |
---|---|---|---|
options | Object |
Accepts the same options as GlueTable , though the following additional attributes are either required or hard-wired: |
|
options.OriginalSql | String |
The SQL query that defines the view. | |
[options.TableType] | String |
'VIRTUAL_VIEW' |
Hard-wired by this shortcut. |
Create a Glue Table.
Pre-configured versions of this shortcut are available for tables stored as line-delimited JSON or ORC:
Param | Type | Default | Description |
---|---|---|---|
options | Object |
Options. | |
options.LogicalName | String |
The logical name of the Glue Table within the CloudFormation template. | |
options.Name | String |
The name of the table. See AWS documentation. | |
options.DatabaseName | String |
The name of the database the table resides in. See AWS documentation. | |
options.Columns | Array.<Object> |
List of the table's columns. See AWS documentation. | |
[options.CatalogId] | String |
AccountId |
The AWS account ID for the account in which to create the table. See AWS documentation. |
[options.Owner] | String |
The table owner. See AWS documentation. | |
[options.Parameters] | Object |
Table parameters. See AWS documentation. | |
[options.PartitionKeys] | Array.<String> |
[] |
List of partitioning columns. See AWS documentation. |
[options.Description] | String |
'Created by the ${AWS::StackName} CloudFormation stack' |
The description of the table. See AWS documentation. |
[options.Retention] | Number |
Retention time for the table. See AWS documentation. | |
[options.TableType] | String |
The type of this table. See AWS documentation. | |
[options.ViewExpandedText] | String |
The expanded text of the view. See AWS documentation. | |
[options.ViewOriginalText] | String |
The original text of the view. See AWS documentation. | |
[options.BucketColumns] | Array.<String> |
List of bucketing columns. See AWS documentation. | |
[options.Compressed] | Boolean |
false |
Whether the data is compressed. See AWS documentation. |
[options.InputFormat] | String |
The table's input format. See AWS documentation. | |
[options.Location] | String |
'' |
The physical location of the table. See AWS documentation. |
[options.NumberOfBuckets] | Number |
0 |
See AWS documentation. |
[options.OutputFormat] | String |
The table's output format. See AWS documentation. | |
[options.StorageParameters] | Object |
Storage parameters. See AWS documentation. | |
[options.SerdeInfo] | Object |
{} |
The serialization/deserialization information. See AWS documentation. |
[options.SkewedInfo] | Object |
Frequent value information. See AWS documentation. | |
[options.SortColumns] | Array.<Object> |
List specifying the sort order. See AWS documentation. | |
[options.StoredAsSubDirectories] | Boolean |
true |
See AWS documentation. |
[options.Condition] | String |
If there is a Condition defined in the template that should control whether to create this database, specify the name of the condition here. See AWS documentation. |
|
[options.DependsOn] | String |
Specify a stack resource dependency to this database. See AWS documentation. |
Example
const cf = require('@mapbox/cloudfriend');
const myTemplate = { ... };
const table = new cf.shortcuts.GlueTable({
LogicalName: 'MyTable',
DatabaseName: 'my_database',
Name: 'my_table',
Columns: [
{ Name: 'column_name', Type: 'string', Comment: 'my_column description' }
]
});
module.exports = cf.merge(myTemplate, table);
Base class for creating a Kinesis Firehouse that can receive records by direct put or by consuming a Kinesis Stream. Each implementing subclass enables writing to a specific destination. Creates a Kinesis Firehouse delivery stream, sets up logging and creates a policy allowing records to be delivered to the delivery stream.
Param | Type | Description |
---|---|---|
options | Object |
Options. |
options.LogicalName | String |
The logical name of the Kinesis Firehouse delivery stream within the CloudFormation template. This is also used to construct the logical names of the other resources. |
[options.KinesisStreamARN] | String | Object |
The ARN of a source Kinesis Stream. |
Baseline CloudFormation resources involved in a Lambda Function. Creates a Log Group, a Role, an Alarm on function errors, and the Lambda Function itself.
Param | Type | Default | Description |
---|---|---|---|
options | Object |
Options. | |
options.LogicalName | String |
The logical name of the Lambda function within the CloudFormation template. This is used to construct the logical names of the other resources, as well as the Lambda function's name. | |
options.Code | Object |
See AWS documentation. | |
[options.DeadLetterConfig] | Object |
See AWS documentation. | |
[options.Description] | String |
'${logical name} in the ${stack name} stack' |
See AWS documentation. |
[options.Environment] | Object |
See AWS documentation. | |
[options.FunctionName] | String |
'${stack name}-${logical name}' |
See AWS documentation. |
[options.Handler] | String |
'index.handler' |
See AWS documentation. |
[options.KmsKeyArn] | String |
See AWS documentation. | |
[options.Layers] | Array.<String> |
See AWS documentation. | |
[options.MemorySize] | Number |
128 |
See AWS documentation. |
[options.ReservedConcurrentExecutions] | Number |
See AWS documentation. | |
[options.Runtime] | String |
'nodejs18.x' |
See AWS documentation. |
[options.Tags] | Array.<Object> |
See AWS documentation. | |
[options.Timeout] | Number |
300 |
See AWS documentation. |
[options.TracingConfig] | Object |
See AWS documentation. | |
[options.VpcConfig] | Object |
See AWS documentation. | |
[options.Condition] | String |
If there is a Condition defined in the template that should control whether to create this Lambda function, specify the name of the condition here. See AWS documentation. |
|
[options.DependsOn] | String |
Specify a stack resource dependency to this Lambda function. See AWS documentation. | |
[options.Statement] | Array.<Object> |
[] |
Policy statements that will be added to a generated IAM role defining the permissions your Lambda function needs to run. Do not use this option when specifying your own role via RoleArn. |
[options.RoleArn] | String |
If specified, the Lambda function will use this role instead of creating a new role. If this option is specified, do not use the Statement option; add the permissions you need to your Role directly. | |
[options.AlarmName] | String |
'${stack name}-${logical name}-Errors-${region}' |
See AWS documentation. |
[options.AlarmDescription] | String |
'Error alarm for ${stack name}-${logical name} lambda function in ${stack name} stack' |
See AWS documentation. |
[options.AlarmActions] | Array.<String> |
[] |
See AWS documentation. |
[options.Period] | Number |
60 |
See AWS documentation. |
[options.EvaluationPeriods] | Number |
1 |
See AWS documentation. |
[options.Statistic] | String |
'Sum' |
See AWS documentation. |
[options.DatapointsToAlarm] | Number |
1 |
See AWS documentation. |
[options.Threshold] | Number |
0 |
See AWS documentation. |
[options.ComparisonOperator] | String |
'GreaterThanThreshold' |
See AWS documentation. |
[options.TreatMissingData] | String |
'notBreaching' |
See AWS documentation. |
[options.EvaluateLowSampleCountPercentile] | String |
See AWS documentation. | |
[options.ExtendedStatistic] | String |
See AWS documentation] | |
[options.OKActions] | Array.<String> |
See AWS documentation. | |
[options.LogRetentionInDays] | Number |
14 |
How long to retain CloudWatch logs for this Lambda function. See AWS Documentation for allowed values. |
Example
const cf = require('@mapbox/cloudfriend');
const myTemplate = { ... };
const lambda = new cf.shortcuts.Lambda({
LogicalName: 'MyLambda',
Code: {
S3Bucket: 'my-code-bucket',
S3Key: 'path/to/code.zip'
}
});
module.exports = cf.merge(myTemplate, lambda);
A Lambda function that runs in response to a log subscription filter. Includes a Log Group, a Role, an Alarm on function errors, a CloudWatch Subscription Filter, and a Lambda permission.
Param | Type | Default | Description |
---|---|---|---|
options | Object |
Extends the options for Lambda with the following additional attributes: |
|
options.LogGroupName | String |
See AWS documentation. | |
[options.FilterPattern] | String |
'' |
See AWS documentation. |
Example
const cf = require('@mapbox/cloudfriend');
const myTemplate = { ... };
const lambda = new cf.shortcuts.LogSubscriptionLambda({
LogicalName: 'MyLambda',
Code: {
S3Bucket: 'my-code-bucket',
S3Key: 'path/to/code.zip'
},
LogGroupName: 'my-log-group'
});
module.exports = cf.merge(myTemplate, lambda);
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 mapping.
Param | Type | Default | Description |
---|---|---|---|
options | Object |
Extends the options for Lambda with the following additional attributes: |
|
options.EventSourceArn | String |
See AWS documentation. | |
options.ReservedConcurrentExecutions | Number |
See AWS documentation. | |
[options.BatchSize] | Number |
1 |
See AWS documentation. |
Example
const cf = require('@mapbox/cloudfriend');
const myTemplate = { ... };
const lambda = new cf.shortcuts.QueueLambda({
LogicalName: 'MyLambda',
Code: {
S3Bucket: 'my-code-bucket',
S3Key: 'path/to/code.zip'
},
EventSourceArn: cf.getAtt('MyQueue', 'Arn'),
ReservedConcurrentExecutions: 30
});
module.exports = cf.merge(myTemplate, lambda);
Creates an SQS queue with an attached dead-letter queue.
Standard (non-FIFO) queues can receive messages through an SNS topic. The
shortcut either creates a new SNS topic that can be used for sending messages
into the queue, or subscribes the queue to an existing SNS topic provided
with the ExistingTopicArn
option. For FIFO queues, no SNS topic is created
and ExistingTopicArn
is ignored.
Param | Type | Default | Description |
---|---|---|---|
options | Object |
Options. | |
options.LogicalName | String |
The logical name of the SQS queue within the CloudFormation template. This is also used to construct the logical names of the other resources. | |
[options.VisibilityTimeout] | Number |
300 |
See AWS documentation. |
[options.maxReceiveCount] | Number |
10 |
See AWS documentation. |
[options.ContentBasedDeduplication] | Boolean |
See AWS documentation. | |
[options.DelaySeconds] | Number |
See AWS documentation. | |
[options.FifoQueue] | Boolean |
See AWS documentation. | |
[options.KmsMasterKeyId] | String |
See AWS documentation. | |
[options.KmsDataKeyReusePeriodSeconds] | Number |
See AWS documentation. | |
[options.MaximumMessageSize] | Number |
See AWS documentation. | |
[options.MessageRetentionPeriod] | Number |
1209600 |
See AWS documentation. |
[options.QueueName] | String |
'${stack name}-${logical name}' |
See AWS documentation. If FifoQueue is true , the suffix .fifo will be added to the queue name. |
[options.ReceiveMessageWaitTimeSeconds] | Number |
See AWS documentation. | |
[options.Condition] | String |
If there is a Condition defined in the template that should control whether to create this SQS queue, specify the name of the condition here. See AWS documentation. |
|
[options.DependsOn] | String |
Specify a stack resource dependency to this SQS queue. See AWS documentation. | |
[options.ExistingTopicArn] | String |
Specify an SNS topic ARN to subscribe the queue to. If this option is provided, TopicName is irrelevant because no new topic is created. This option is ignored if FifoQueue: true , because FIFO queues cannot subscribe to SNS topics. |
|
[options.TopicName] | String |
'${stack name}-${logical name}' |
See AWS documentation. This option is ignored if FifoQueue: true , because FIFO queues cannot subscribe to SNS topics. |
[options.DisplayName] | String |
See AWS documentation. | |
[options.DeadLetterVisibilityTimeout] | Number |
300 |
VisibilityTimeout for the dead-letter queue. |
Example
const cf = require('@mapbox/cloudfriend');
const myTemplate = { ... };
const queue = new cf.shortcuts.Queue({
LogicalName: 'MyQueue'
});
module.exports = cf.merge(myTemplate, queue);
Create an IAM role.
Param | Type | Default | Description |
---|---|---|---|
options | Object |
Options. | |
options.LogicalName | String |
The logical name of the IAM role within the CloudFormation template. | |
options.AssumeRolePrincipals | Array.<Object> |
An array of principal objects defining entities able to assume this role. Will be included in the role's AssumeRolePolicyDocument . |
|
[options.Statement] | Array.<Object> |
[] |
An array of permissions statements to be included in the PolicyDocument . |
[options.ManagedPolicyArns] | Array.<String> |
See AWS documentation. | |
[options.MaxSessionDuration] | Number |
See AWS documentation. | |
[options.Path] | String |
See AWS documentation. | |
[options.RoleName] | String |
See AWS documentation. | |
[options.Tags] | Array.<Object> |
See AWS documentation. | |
[options.Condition] | String |
If there is a Condition defined in the template that should control whether to create this IAM role, specify the name of the condition here. See AWS documentation. |
|
[options.DependsOn] | String |
Specify a stack resource dependency to this IAM role. See AWS documentation. |
Example
const cf = require('@mapbox/cloudfriend');
const myTemplate = { ... };
const role = new cf.shortcuts.Role({
LogicalName: 'MyRole',
AssumeRolePrincipals: [
{ Service: 'ec2.amazonaws.com' }
],
Statement: [
{
Effect: 'Allow',
Action: 's3:GetObject',
Resource: 'arn:aws:s3:::my-bucket/my/data.tar.gz'
}
]
});
module.exports = cf.merge(myTemplate, role);
Creates a Kinesis Firehouse that can receive records by direct put or by consuming a Kinesis Stream
and writes out to the specific S3 destination. Creates a Kinesis Firehouse delivery stream,
sets up logging, and creates a policy allowing records to be delivered to the delivery stream.
Also creates a CloudWatch alarm on the DeliveryToS3.DataFreshness
metric -- the age
of the oldest record in Kinesis Data Firehose (from entering the Kinesis Data Firehose until now).
By default, if that metric exceeds double the BufferingIntervalInSeconds
, the
alarm is triggered.
Param | Type | Default | Description |
---|---|---|---|
options | Object |
Options. | |
options.LogicalName | String |
The logical name of the Kinesis Firehouse delivery stream within the CloudFormation template. This is also used to construct the logical names of the other resources. | |
options.DestinationBucket | String |
The name of the S3 bucket to write to. | |
[options.Prefix] | String |
'raw/${logical name}/' |
The prefix path (folder) within the DestinationBucket to write to. |
[options.KinesisStreamARN] | String | Object |
The ARN of a source Kinesis Stream. | |
[options.BufferingIntervalInSeconds] | Number |
900 |
See AWS documentation. |
[options.BufferingSizeInMBs] | Number |
128 |
See AWS documentation. |
[options.AlarmName] | String |
'${stack name}-${logical name}-Freshness-${region}' |
See AWS documentation. |
[options.AlarmDescription] | String |
'Freshness alarm for ${stack name}-${logical name} kinesis firehose in ${stack name} stack' |
See AWS documentation. |
[options.AlarmActions] | Array.<String> |
[] |
See AWS documentation. |
[options.Period] | Number |
60 |
See AWS documentation. |
[options.EvaluationPeriods] | Number |
1 |
See AWS documentation. |
[options.Statistic] | String |
'Maximum' |
See AWS documentation. |
[options.Threshold] | Number |
(BufferingIntervalInSeconds * 2) |
See AWS documentation. |
[options.ComparisonOperator] | String |
'GreaterThanThreshold' |
See AWS documentation. |
[options.TreatMissingData] | String |
'notBreaching' |
See AWS documentation. |
[options.EvaluateLowSampleCountPercentile] | String |
See AWS documentation. | |
[options.ExtendedStatistic] | String |
See AWS documentation] | |
[options.OKActions] | Array.<String> |
See AWS documentation. |
Example
const cf = require('@mapbox/cloudfriend');
const myTemplate = { ... };
const firehose = new cf.shortcuts.S3KinesisFirehose({
LogicalName: 'MyKinesisFirehose',
DestinationBucket: 'mah-bukkit'
});
module.exports = cf.merge(myTemplate, firehose);
A Lambda function that runs on in response to a CloudWatch Event. Includes a Log Group, a Role, an Alarm on function errors, a CloudWatch Event Rule, and a Lambda permission.
Param | Type | Default | Description |
---|---|---|---|
options | Object |
Extends the options for Lambda with the following additional attributes: |
|
options.ScheduleExpression | String |
See AWS documentation. | |
[options.ScheduleRoleArn] | String |
If specified, the eventbridge scheduler schedule will use this role to invoke your lambda . If not specified a service role with the correct scoped permissions is created for you. See AWS documentation | |
[options.ScheduleGroupName] | String |
If specified, the eventbridge scheduler schedule is associated with this preexisting schedule group. If not specified the schedule is associated with the default schedule group. Note you cannot change a schedule's schedule group once it has been already associated with a schedule group. See AWS documentation. | |
[options.State] | String |
'ENABLED' |
See AWS documentation. |
Example
const cf = require('@mapbox/cloudfriend');
const myTemplate = { ... };
// A scheduler service role is already created for you internally with the correct permissions
const lambda = new cf.shortcuts.ScheduledLambda({
LogicalName: 'MyLambda',
Code: {
S3Bucket: 'my-code-bucket',
S3Key: 'path/to/code.zip'
},
ScheduleExpression: 'cron(45 * * * ? *)',
});
module.exports = cf.merge(myTemplate, lambda);
Example
const cf = require('@mapbox/cloudfriend');
const myTemplate = { ... };
// If you are creating your own scheduler service role, be sure your permissions are correct!
const role = new cf.shortcuts.ServiceRole({
LogicalName: 'MyRole',
Service: 'scheduler.amazonaws.com',
Statement: [
{
Effect: 'Allow',
Action: 'lambda:InvokeFunction',
Resource: cf.sub('arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${AWS::StackName}-*')
}
]
});
const lambda = new cf.shortcuts.ScheduledLambda({
LogicalName: 'MyLambda',
Code: {
S3Bucket: 'my-code-bucket',
S3Key: 'path/to/code.zip'
},
ScheduleRoleArn: cf.getAtt('MyRole', 'Arn'),
ScheduleExpression: 'rate(1 hour)',
});
module.exports = cf.merge(myTemplate, role, lambda);
Create an IAM role that will be assumed by an AWS service, e.g. Lambda or ECS.
Param | Type | Description |
---|---|---|
options | Object |
Extends the options for Role . You do not need to provide an AssumeRolePrincipals attribute, but do need to include the following additional attributes: |
options.Service | String |
The name of the AWS service that will assume this role, e.g. lambda . |
Example
const cf = require('@mapbox/cloudfriend');
const myTemplate = { ... };
const role = new cf.shortcuts.ServiceRole({
LogicalName: 'MyRole',
Service: 'lambda',
Statement: [
{
Effect: 'Allow',
Action: 's3:GetObject',
Resource: 'arn:aws:s3:::my-bucket/my/data.tar.gz'
}
]
});
module.exports = cf.merge(myTemplate, role);
A Lambda function that runs in response to events in a DynamoDB or Kinesis stream. Includes a Log Group, a Role, an Alarm on function errors, and an event source mapping.
Param | Type | Default | Description |
---|---|---|---|
options | Object |
Extends the options for Lambda with the following additional attributes: |
|
options.EventSourceArn | String |
See AWS documentation. | |
[options.BatchSize] | Number |
1 |
See AWS documentation. |
[options.MaximumBatchingWindowInSeconds] | Number |
See AWS documentation. | |
[options.Enabled] | Boolean |
true |
See AWS documentation. |
[options.StartingPosition] | String |
'LATEST' |
See AWS documentation. |
[options.FilterCriteria] | Object |
See AWS documentation. |
Example
const cf = require('@mapbox/cloudfriend');
const myTemplate = { ... };
const lambda = new cf.shortcuts.StreamLambda({
LogicalName: 'MyLambda',
Code: {
S3Bucket: 'my-code-bucket',
S3Key: 'path/to/code.zip'
},
EventSourceArn: cf.getAtt('MyStream', 'Arn'),
});
// This lambda only gets invoked for 'INSERT' events for the DynamoDb event source
const lambdaWithFilterCriteria = new cf.shortcuts.StreamLambda({
LogicalName: 'MyLambdaWithFilterCriteria',
Code: {
S3Bucket: 'my-code-bucket',
S3Key: 'path/to/code.zip'
},
EventSourceArn: cf.getAtt('MyDynamoDbStream', 'Arn'),
FilterCriteria: {
Filters: [
{
Pattern: JSON.stringify({ eventName: ['INSERT'] }),
}
]
}
});
module.exports = cf.merge(myTemplate, lambda, lambdaWithFilterCriteria);