-
Notifications
You must be signed in to change notification settings - Fork 820
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add User Migration trigger option to Cognito
- Loading branch information
Showing
7 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
...egory-auth/provider-utils/awscloudformation/triggers/UserMigration/UserMigration.map.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,2 @@ | ||
{ | ||
} |
204 changes: 204 additions & 0 deletions
204
.../awscloudformation/triggers/UserMigration/cloudformation-templates/UserMigration.json.ejs
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,204 @@ | ||
{ | ||
"AWSTemplateFormatVersion": "2010-09-09", | ||
"Description": "Lambda resource stack creation using Amplify CLI", | ||
"Parameters": { | ||
"modules": { | ||
"Type": "String", | ||
"Default": "", | ||
"Description": "Comma-delimited list of modules to be executed by a lambda trigger. Sent to resource as an env variable." | ||
}, | ||
"resourceName": { | ||
"Type": "String", | ||
"Default": "" | ||
}, | ||
"trigger": { | ||
"Type": "String", | ||
"Default": "true" | ||
}, | ||
"functionName": { | ||
"Type": "String", | ||
"Default": "" | ||
}, | ||
"roleName": { | ||
"Type": "String", | ||
"Default": "" | ||
}, | ||
"parentResource": { | ||
"Type": "String", | ||
"Default": "" | ||
}, | ||
"parentStack": { | ||
"Type": "String", | ||
"Default": "" | ||
}, | ||
"env": { | ||
"Type": "String" | ||
}<%if (props.dependsOn && props.dependsOn.length > 0) { %>,<% } %> | ||
<% if (props.dependsOn) { %> | ||
<% for(var i=0; i < props.dependsOn.length; i++) { %> | ||
<% for(var j=0; j < props.dependsOn[i].attributes.length; j++) { %> | ||
"<%= props.dependsOn[i].category %><%= props.dependsOn[i].resourceName %><%= props.dependsOn[i].attributes[j] %>": { | ||
"Type": "String", | ||
"Default": "<%= props.dependsOn[i].category %><%= props.dependsOn[i].resourceName %><%= props.dependsOn[i].attributes[j] %>" | ||
}<%if (i !== props.dependsOn.length - 1 || j !== props.dependsOn[i].attributes.length - 1) { %>,<% } %> | ||
<% } %> | ||
<% } %> | ||
<% } %> | ||
}, | ||
"Conditions": { | ||
"ShouldNotCreateEnvResources": { | ||
"Fn::Equals": [ | ||
{ | ||
"Ref": "env" | ||
}, | ||
"NONE" | ||
] | ||
} | ||
}, | ||
"Resources": { | ||
"LambdaFunction": { | ||
"Type": "AWS::Lambda::Function", | ||
"Metadata": { | ||
"aws:asset:path": "./src", | ||
"aws:asset:property": "Code" | ||
}, | ||
"Properties": { | ||
"Handler": "index.handler", | ||
"FunctionName": { | ||
"Fn::If": [ | ||
"ShouldNotCreateEnvResources", | ||
"<%= props.functionName %>", | ||
{ | ||
|
||
"Fn::Join": [ | ||
"", | ||
[ | ||
"<%= props.functionName %>", | ||
"-", | ||
{ | ||
"Ref": "env" | ||
} | ||
] | ||
] | ||
} | ||
] | ||
}, | ||
"Environment": { | ||
"Variables" : { | ||
"ENV": { | ||
"Ref": "env" | ||
}, | ||
"MODULES": { | ||
"Ref": "modules" | ||
}, | ||
"REGION": { | ||
"Ref": "AWS::Region" | ||
} | ||
} | ||
}, | ||
"Role": { "Fn::GetAtt" : ["LambdaExecutionRole", "Arn"] }, | ||
"Runtime": "nodejs18.x", | ||
"Timeout": 25 | ||
} | ||
}, | ||
"LambdaExecutionRole": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"RoleName": { | ||
"Fn::If": [ | ||
"ShouldNotCreateEnvResources", | ||
"<%=props.roleName %>", | ||
{ | ||
|
||
"Fn::Join": [ | ||
"", | ||
[ | ||
"<%=props.roleName %>", | ||
"-", | ||
{ | ||
"Ref": "env" | ||
} | ||
] | ||
] | ||
} | ||
] | ||
}, | ||
"AssumeRolePolicyDocument": { | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": [ | ||
"lambda.amazonaws.com" | ||
] | ||
}, | ||
"Action": [ | ||
"sts:AssumeRole" | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
,"lambdaexecutionpolicy": { | ||
"DependsOn": ["LambdaExecutionRole"], | ||
"Type": "AWS::IAM::Policy", | ||
"Properties": { | ||
"PolicyName": "lambda-execution-policy", | ||
"Roles": [{ "Ref": "LambdaExecutionRole" }], | ||
"PolicyDocument": { | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action":["logs:CreateLogGroup", | ||
"logs:CreateLogStream", | ||
"logs:PutLogEvents"], | ||
"Resource": { "Fn::Sub" : [ "arn:aws:logs:${region}:${account}:log-group:/aws/lambda/${lambda}:log-stream:*", { "region": {"Ref": "AWS::Region"}, "account": {"Ref": "AWS::AccountId"}, "lambda": {"Ref": "LambdaFunction"}} ]} | ||
} | ||
] | ||
} | ||
} | ||
}<% if (props.categoryPolicies && props.categoryPolicies.length > 0 ) { %> | ||
,"AmplifyResourcesPolicy": { | ||
"DependsOn": ["LambdaExecutionRole"], | ||
"Type": "AWS::IAM::Policy", | ||
"Properties": { | ||
"PolicyName": "amplify-lambda-execution-policy", | ||
"Roles": [{ "Ref": "LambdaExecutionRole" }], | ||
"PolicyDocument": { | ||
"Version": "2012-10-17", | ||
"Statement": <%- JSON.stringify(props.categoryPolicies) %> | ||
} | ||
} | ||
} | ||
<% } %> | ||
}, | ||
"Outputs": { | ||
"Name": { | ||
"Value": { | ||
"Ref": "LambdaFunction" | ||
} | ||
}, | ||
"Arn": { | ||
"Value": {"Fn::GetAtt": ["LambdaFunction", "Arn"]} | ||
}, | ||
"LambdaExecutionRole": { | ||
"Value": { | ||
"Ref": "LambdaExecutionRole" | ||
} | ||
}, | ||
"LambdaExecutionRoleArn": { | ||
"Value": { | ||
"Fn::GetAtt": ["LambdaExecutionRole", "Arn"] | ||
} | ||
}, | ||
"Region": { | ||
"Value": { | ||
"Ref": "AWS::Region" | ||
} | ||
} | ||
} | ||
} | ||
|
5 changes: 5 additions & 0 deletions
5
.../provider-utils/awscloudformation/triggers/UserMigration/function-template-dir/event.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,5 @@ | ||
{ | ||
"key1": "value1", | ||
"key2": "value2", | ||
"key3": "value3" | ||
} |
13 changes: 13 additions & 0 deletions
13
...der-utils/awscloudformation/triggers/UserMigration/function-template-dir/package.json.ejs
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,13 @@ | ||
{ | ||
"name": "<%= props.functionName %>", | ||
"version": "2.0.0", | ||
"description": "Lambda function generated by Amplify", | ||
"main": "index.js", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"axios": "latest" | ||
}, | ||
"devDependencies": { | ||
"@types/aws-lambda": "^8.10.92" | ||
} | ||
} |
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