-
Notifications
You must be signed in to change notification settings - Fork 819
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ability to add custom EventSource and lambda triggers via ampli…
…fy add function, kinesis support in analytics category (#2463)
- Loading branch information
1 parent
12345da
commit b25cfd0
Showing
36 changed files
with
1,984 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/amplify-category-analytics/commands/analytics/update.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const subcommand = 'update'; | ||
const category = 'analytics'; | ||
|
||
module.exports = { | ||
name: subcommand, | ||
alias: ['configure'], | ||
run: async context => { | ||
const { amplify } = context; | ||
const servicesMetadata = amplify.readJsonFile(`${__dirname}/../../provider-utils/supported-services.json`); | ||
|
||
return amplify | ||
.serviceSelectionPrompt(context, category, servicesMetadata) | ||
.then(result => { | ||
const options = { | ||
service: result.service, | ||
providerPlugin: result.providerName, | ||
}; | ||
|
||
const providerController = require(`../../provider-utils/${result.providerName}/index`); | ||
if (!providerController) { | ||
context.print.error('Provider not configured for this category'); | ||
return; | ||
} | ||
|
||
return providerController.updateResource(context, category, result.service, options); | ||
}) | ||
.then(resourceName => { | ||
const { print } = context; | ||
print.success(`Successfully updated resource ${resourceName} locally`); | ||
print.info(''); | ||
print.success('Some next steps:'); | ||
print.info('"amplify push" will build all your local backend resources and provision it in the cloud'); | ||
print.info( | ||
'"amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud', | ||
); | ||
print.info(''); | ||
}) | ||
.catch(err => { | ||
context.print.info(err.stack); | ||
context.print.error(`There was an error updating the ${category} resource`); | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const open = require('open'); | ||
const constants = require('./constants'); | ||
|
||
function console(context) { | ||
const amplifyMeta = context.amplify.getProjectMeta(); | ||
const { envName } = context.amplify.getEnvInfo(); | ||
const region = context.amplify.getEnvDetails()[envName].awscloudformation.Region; | ||
|
||
const kinesisApp = scanCategoryMetaForKinesis(amplifyMeta[constants.CategoryName]); | ||
if (kinesisApp) { | ||
const { Id } = kinesisApp; | ||
const consoleUrl = `https://${region}.console.aws.amazon.com/kinesis/home?region=${region}#/streams/details?streamName=${Id}&tab=details`; | ||
open(consoleUrl, { wait: false }); | ||
} else { | ||
context.print.error('Kinesis is not enabled in the cloud.'); | ||
} | ||
} | ||
|
||
function scanCategoryMetaForKinesis(categoryMeta) { | ||
// single kinesis resource for now | ||
let result; | ||
if (categoryMeta) { | ||
const services = Object.keys(categoryMeta); | ||
for (let i = 0; i < services.length; i++) { | ||
const serviceMeta = categoryMeta[services[i]]; | ||
if (serviceMeta.service === constants.KinesisName && serviceMeta.output && serviceMeta.output.kinesisStreamId) { | ||
result = { | ||
Id: serviceMeta.output.kinesisStreamId, | ||
}; | ||
if (serviceMeta.output.Name) { | ||
result.Name = serviceMeta.output.Name; | ||
} else if (serviceMeta.output.appName) { | ||
result.Name = serviceMeta.output.appName; | ||
} | ||
|
||
if (serviceMeta.output.Region) { | ||
result.Region = serviceMeta.output.Region; | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
function hasResource(context) { | ||
const amplifyMeta = context.amplify.getProjectMeta(); | ||
return scanCategoryMetaForKinesis(amplifyMeta[constants.CategoryName]) !== undefined; | ||
} | ||
|
||
module.exports = { | ||
console, | ||
hasResource, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...der-utils/awscloudformation/cloudformation-templates/kinesis-cloudformation-template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
{ | ||
"AWSTemplateFormatVersion": "2010-09-09", | ||
"Description": "Pinpoint resource stack creation using Amplify CLI", | ||
"Parameters": { | ||
"env": { | ||
"Type": "String" | ||
}, | ||
"kinesisStreamName": { | ||
"Type": "String" | ||
}, | ||
"kinesisStreamShardCount": { | ||
"Type": "Number", | ||
"Default": 1 | ||
}, | ||
"authPolicyName": { | ||
"Type": "String" | ||
}, | ||
"unauthPolicyName": { | ||
"Type": "String" | ||
}, | ||
"authRoleName": { | ||
"Type": "String" | ||
}, | ||
"unauthRoleName": { | ||
"Type": "String" | ||
} | ||
}, | ||
"Conditions": { | ||
"ShouldNotCreateEnvResources": { | ||
"Fn::Equals": [ | ||
{ "Ref": "env" }, | ||
"NONE" | ||
] | ||
} | ||
}, | ||
"Resources": { | ||
"KinesisStream": { | ||
"Type": "AWS::Kinesis::Stream", | ||
"Properties": { | ||
"Name": { | ||
"Fn::Join": [ | ||
"-", | ||
[ | ||
{ "Ref": "kinesisStreamName" }, | ||
{ "Ref": "env"} | ||
] | ||
] | ||
}, | ||
"ShardCount": { "Ref": "kinesisStreamShardCount" } | ||
} | ||
}, | ||
"CognitoUnauthPolicy": { | ||
"Type": "AWS::IAM::Policy", | ||
"Properties": { | ||
"PolicyName": {"Ref": "unauthPolicyName" }, | ||
"Roles": [ | ||
{"Ref": "unauthRoleName" } | ||
], | ||
"PolicyDocument": { | ||
"Version": "2012-10-17", | ||
"Statement": [{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"kinesis:PutRecord", | ||
"kinesis:PutRecords" | ||
], | ||
"Resource": { | ||
"Fn::GetAtt": ["KinesisStream", "Arn"] | ||
} | ||
}] | ||
} | ||
} | ||
}, | ||
"CognitoAuthPolicy": { | ||
"Type": "AWS::IAM::Policy", | ||
"Properties": { | ||
"PolicyName": {"Ref": "authPolicyName" }, | ||
"Roles": [ | ||
{"Ref": "authRoleName" } | ||
], | ||
"PolicyDocument": { | ||
"Version": "2012-10-17", | ||
"Statement": [{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"kinesis:PutRecord", | ||
"kinesis:PutRecords" | ||
], | ||
"Resource": { | ||
"Fn::GetAtt": ["KinesisStream", "Arn"] | ||
} | ||
}] | ||
} | ||
} | ||
} | ||
}, | ||
"Outputs": { | ||
"kinesisStreamArn": { | ||
"Value": {"Fn::GetAtt": ["KinesisStream", "Arn"] } | ||
}, | ||
"kinesisStreamId": { | ||
"Value": {"Ref": "KinesisStream" } | ||
}, | ||
"kinesisStreamShardCount": { | ||
"Value": {"Ref": "kinesisStreamShardCount" } | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...fy-category-analytics/provider-utils/awscloudformation/default-values/kinesis-defaults.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const uuid = require('uuid'); | ||
|
||
const getAllDefaults = project => { | ||
const appName = project.projectConfig.projectName.toLowerCase(); | ||
const [shortId] = uuid().split('-'); | ||
|
||
const authRoleName = { | ||
Ref: 'AuthRoleName', | ||
}; | ||
|
||
const unauthRoleName = { | ||
Ref: 'UnauthRoleName', | ||
}; | ||
|
||
const defaults = { | ||
kinesisStreamName: `${appName}Kinesis`, | ||
kinesisStreamShardCount: 1, | ||
authRoleName, | ||
unauthRoleName, | ||
authPolicyName: `kinesis_amplify_${shortId}`, | ||
unauthPolicyName: `kinesis_amplify_${shortId}`, | ||
}; | ||
|
||
return defaults; | ||
}; | ||
|
||
module.exports = { | ||
getAllDefaults, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.