Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mapbox/magic-cfn-resources

Package Overview
Dependencies
Maintainers
163
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mapbox/magic-cfn-resources - npm Package Compare versions

Comparing version 1.2.3 to 1.2.5

package-lock.json

12

changelog.md

@@ -0,1 +1,11 @@

### 1.2.4
Rewrote parts of `/lib/build.js` so that references to SpotFleet specific properties were not evaluated for non-spotfleets
### 1.2.4
Adjusted Custom Resource names from 'Custom::MagicCfnResource' to Custom::CustomResourceName, IE a SpotFleet will be Custom::SpotFleet
### 1.2.3
Fixed cloudfriend being a dev dependency
### 1.2.2

@@ -7,2 +17,2 @@

Updated role resources in spotfleet build [function](https://github.com/mapbox/magic-cfn-resources/pull/14).
Updated role resources in spotfleet build [function](https://github.com/mapbox/magic-cfn-resources/pull/14).

95

lib/build.js

@@ -37,4 +37,42 @@ // builds cfn resources for lambda function

const roles = {
SnsSubscription: {
CustomResource[`${params.LogicalName}Role`] = role(params);
CustomResource[`${params.LogicalName}Function`] = {
Type: 'AWS::Lambda::Function',
// #### Properties
Properties: {
// - Code: You must upload your Lambda function as a .zip file
// to S3, and refer to it here.
Code: {
S3Bucket: params.S3Bucket,
S3Key: params.S3Key
},
// - Role: Refers to the ARN of the Role defined above.
Role: cf.getAtt(`${params.LogicalName}Role`, 'Arn'),
// - Other parameters as described by
// [the AWS documentation](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html).
Description: `Manages ${params.CustomResourceName}`,
Handler: params.Handler,
MemorySize: 128,
Runtime: 'nodejs6.10',
Timeout: 30
}
};
CustomResource[params.LogicalName] = {
Type: cf.join('',['Custom::',params.CustomResourceName]),
Properties: Object.assign({ ServiceToken: cf.getAtt(`${params.LogicalName}Function`, 'Arn')}, params.Properties)
};
if (params.Condition) {
CustomResource[`${params.LogicalName}Role`]['Condition'] = params.Condition;
CustomResource[`${params.LogicalName}Function`]['Condition'] = params.Condition;
CustomResource[params.LogicalName]['Condition'] = params.Condition;
}
return { Resources: CustomResource };
}
function role(params) {
switch (params.CustomResourceName) {
case 'SnsSubscription':
return {
Type: 'AWS::IAM::Role',

@@ -86,4 +124,5 @@ Properties: {

}
},
DynamoDBStreamLabel: {
};
case 'DynamoDBStreamLabel':
return {
Type: 'AWS::IAM::Role',

@@ -130,4 +169,5 @@ Properties: {

}
},
StackOutputs: {
};
case 'StackOutputs':
return {
Type: 'AWS::IAM::Role',

@@ -174,4 +214,5 @@ Properties: {

}
},
SpotFleet: {
};
case 'SpotFleet':
return {
Type: 'AWS::IAM::Role',

@@ -231,38 +272,6 @@ Properties: {

}
}
};
CustomResource[`${params.LogicalName}Role`] = roles[params.CustomResourceName];
CustomResource[`${params.LogicalName}Function`] = {
Type: 'AWS::Lambda::Function',
// #### Properties
Properties: {
// - Code: You must upload your Lambda function as a .zip file
// to S3, and refer to it here.
Code: {
S3Bucket: params.S3Bucket,
S3Key: params.S3Key
},
// - Role: Refers to the ARN of the Role defined above.
Role: cf.getAtt(`${params.LogicalName}Role`, 'Arn'),
// - Other parameters as described by
// [the AWS documentation](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html).
Description: `Manages ${params.CustomResourceName}`,
Handler: params.Handler,
MemorySize: 128,
Runtime: 'nodejs6.10',
Timeout: 30
}
};
CustomResource[params.LogicalName] = {
Type: 'Custom::MagicCfnResource',
Properties: Object.assign({ ServiceToken: cf.getAtt(`${params.LogicalName}Function`, 'Arn')}, params.Properties)
};
if (params.Condition) {
CustomResource[`${params.LogicalName}Role`]['Condition'] = params.Condition;
CustomResource[`${params.LogicalName}Function`]['Condition'] = params.Condition;
CustomResource[params.LogicalName]['Condition'] = params.Condition;
};
default:
throw new Error('Unknown resource name');
}
return { Resources: CustomResource };
}
{
"name": "@mapbox/magic-cfn-resources",
"version": "1.2.3",
"version": "1.2.5",
"description": "Build Lambda-backed custom CloudFormation resources",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -207,4 +207,29 @@ const build = require('../lib/build').build;

test('[build] success on SnsSubscription', assert => {
const template = build({
CustomResourceName: 'SnsSubscription',
LogicalName: 'SnsSubscriptionLogicalName',
S3Key: 'lambda/code',
S3Bucket: 'code',
Handler: 'my.handler',
Properties: {
Protocol: 'email',
TopicArn: 'arn:aws:sns:us-east-1:special-topic',
Endpoint: 'someone@mapbox.com'
}
});
assert.deepEquals(Object.keys(template.Resources), ['SnsSubscriptionLogicalNameRole', 'SnsSubscriptionLogicalNameFunction', 'SnsSubscriptionLogicalName'], 'role, function, and custom resource use logical name');
assert.equals(template.Resources.SnsSubscriptionLogicalNameRole.Type, 'AWS::IAM::Role', 'Type is AWS::IAM::Role');
assert.equals(template.Resources.SnsSubscriptionLogicalNameFunction.Type, 'AWS::Lambda::Function', 'Type is AWS::Lambda::Function');
assert.equals(template.Resources.SnsSubscriptionLogicalNameFunction.Properties.Code.S3Bucket, 'code', 'S3Bucket is params.S3Bucket');
assert.deepEquals(template.Resources.SnsSubscriptionLogicalNameFunction.Properties.Code.S3Key, 'lambda/code', 'S3Key is params.S3Key');
assert.equals(template.Resources.SnsSubscriptionLogicalNameFunction.Properties.Handler, 'my.handler', 'Handler is params.Handler');
assert.end();
});
test('[build] success with Conditional', assert => {
const template = build({
var params = {
CustomResourceName: 'SpotFleet',

@@ -225,7 +250,9 @@ LogicalName: 'SpotFleetLogicalName',

Condition: 'Conditional'
});
};
const template = build(params);
assert.equals(template.Resources.SpotFleetLogicalNameRole.Condition, 'Conditional', 'Conditional in Role');
assert.equals(template.Resources.SpotFleetLogicalNameFunction.Condition, 'Conditional', 'Conditional in Function');
assert.equals(template.Resources.SpotFleetLogicalName.Condition, 'Conditional', 'Conditional in Custom Resource');
assert.deepEqual(template.Resources.SpotFleetLogicalName.Type, { 'Fn::Join': [ '', [ 'Custom::', params.CustomResourceName ] ] }, 'Type equals Custom::params.CustomResourceName');
assert.end();
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc