Skip to content

Commit

Permalink
Created lambda for delete user (#1206)
Browse files Browse the repository at this point in the history
* Refactored GenericDirectoryScreen

* Created deleteJCUser function
  • Loading branch information
itbel authored Jul 26, 2022
1 parent e12a8df commit f451d85
Show file tree
Hide file tree
Showing 19 changed files with 1,721 additions and 72 deletions.
22 changes: 22 additions & 0 deletions amplify/backend/backend-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,28 @@
"providerPlugin": "awscloudformation",
"service": "LambdaLayer",
"build": true
},
"deleteJCUser": {
"build": true,
"providerPlugin": "awscloudformation",
"service": "Lambda",
"dependsOn": [
{
"category": "auth",
"resourceName": "jcmobile",
"attributes": [
"UserPoolId"
]
},
{
"category": "api",
"resourceName": "jcmobile",
"attributes": [
"GraphQLAPIIdOutput",
"GraphQLAPIEndpointOutput"
]
}
]
}
},
"auth": {
Expand Down
6 changes: 6 additions & 0 deletions amplify/backend/function/deleteJCUser/amplify.state
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pluginId": "amplify-nodejs-function-runtime-provider",
"functionRuntime": "nodejs",
"useLegacyBuild": true,
"defaultEditorFile": "src/index.js"
}
6 changes: 6 additions & 0 deletions amplify/backend/function/deleteJCUser/custom-policies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"Action": [],
"Resource": []
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,313 @@
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "{\"createdOn\":\"Mac\",\"createdBy\":\"Amplify\",\"createdWith\":\"7.6.25\",\"stackType\":\"function-Lambda\",\"metadata\":{}}",
"Parameters": {
"CloudWatchRule": {
"Type": "String",
"Default": "NONE",
"Description": " Schedule Expression"
},
"deploymentBucketName": {
"Type": "String"
},
"env": {
"Type": "String"
},
"s3Key": {
"Type": "String"
},
"authjcmobileUserPoolId": {
"Type": "String",
"Default": "authjcmobileUserPoolId"
},
"apijcmobileGraphQLAPIIdOutput": {
"Type": "String",
"Default": "apijcmobileGraphQLAPIIdOutput"
},
"apijcmobileGraphQLAPIEndpointOutput": {
"Type": "String",
"Default": "apijcmobileGraphQLAPIEndpointOutput"
}
},
"Conditions": {
"ShouldNotCreateEnvResources": {
"Fn::Equals": [
{
"Ref": "env"
},
"NONE"
]
}
},
"Resources": {
"LambdaFunction": {
"Type": "AWS::Lambda::Function",
"Metadata": {
"aws:asset:path": "./src",
"aws:asset:property": "Code"
},
"Properties": {
"Code": {
"S3Bucket": {
"Ref": "deploymentBucketName"
},
"S3Key": {
"Ref": "s3Key"
}
},
"Handler": "index.handler",
"FunctionName": {
"Fn::If": [
"ShouldNotCreateEnvResources",
"deleteJCUser",
{
"Fn::Join": [
"",
[
"deleteJCUser",
"-",
{
"Ref": "env"
}
]
]
}
]
},
"Environment": {
"Variables": {
"ENV": {
"Ref": "env"
},
"REGION": {
"Ref": "AWS::Region"
},
"AUTH_JCMOBILE_USERPOOLID": {
"Ref": "authjcmobileUserPoolId"
},
"API_JCMOBILE_GRAPHQLAPIIDOUTPUT": {
"Ref": "apijcmobileGraphQLAPIIdOutput"
},
"API_JCMOBILE_GRAPHQLAPIENDPOINTOUTPUT": {
"Ref": "apijcmobileGraphQLAPIEndpointOutput"
}
}
},
"Role": {
"Fn::GetAtt": [
"LambdaExecutionRole",
"Arn"
]
},
"Runtime": "nodejs14.x",
"Layers": [],
"Timeout": 25
}
},
"LambdaExecutionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"RoleName": {
"Fn::If": [
"ShouldNotCreateEnvResources",
"jcmobileLambdaRole5969545f",
{
"Fn::Join": [
"",
[
"jcmobileLambdaRole5969545f",
"-",
{
"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"
}
}
]
}
}
]
}
}
},
"AmplifyResourcesPolicy": {
"DependsOn": [
"LambdaExecutionRole"
],
"Type": "AWS::IAM::Policy",
"Properties": {
"PolicyName": "amplify-lambda-execution-policy",
"Roles": [
{
"Ref": "LambdaExecutionRole"
}
],
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"cognito-identity:Describe*",
"cognito-identity:Get*",
"cognito-identity:List*",
"cognito-idp:Describe*",
"cognito-idp:AdminGetDevice",
"cognito-idp:AdminGetUser",
"cognito-idp:AdminList*",
"cognito-idp:List*",
"cognito-sync:Describe*",
"cognito-sync:Get*",
"cognito-sync:List*",
"iam:ListOpenIdConnectProviders",
"iam:ListRoles",
"sns:ListPlatformApplications",
"cognito-idp:DeleteUserPoolDomain",
"cognito-idp:DeleteResourceServer",
"cognito-idp:DeleteGroup",
"cognito-idp:AdminDeleteUserAttributes",
"cognito-idp:DeleteUserPoolClient",
"cognito-idp:DeleteUserAttributes",
"cognito-idp:DeleteUserPool",
"cognito-idp:AdminDeleteUser",
"cognito-idp:DeleteIdentityProvider",
"cognito-idp:DeleteUser"
],
"Resource": [
{
"Fn::Join": [
"",
[
"arn:aws:cognito-idp:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":userpool/",
{
"Ref": "authjcmobileUserPoolId"
}
]
]
}
]
},
{
"Effect": "Allow",
"Action": [
"appsync:Get*",
"appsync:List*",
"appsync:Delete*"
],
"Resource": [
{
"Fn::Join": [
"",
[
"arn:aws:appsync:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":apis/",
{
"Ref": "apijcmobileGraphQLAPIIdOutput"
}
]
]
}
]
}
]
}
}
}
},
"Outputs": {
"Name": {
"Value": {
"Ref": "LambdaFunction"
}
},
"Arn": {
"Value": {
"Fn::GetAtt": [
"LambdaFunction",
"Arn"
]
}
},
"Region": {
"Value": {
"Ref": "AWS::Region"
}
},
"LambdaExecutionRole": {
"Value": {
"Ref": "LambdaExecutionRole"
}
}
}
}
17 changes: 17 additions & 0 deletions amplify/backend/function/deleteJCUser/function-parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"lambdaLayers": [],
"permissions": {
"auth": {
"jcmobile": [
"read",
"delete"
]
},
"api": {
"jcmobile": [
"read",
"delete"
]
}
}
}
3 changes: 3 additions & 0 deletions amplify/backend/function/deleteJCUser/src/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"userID": ""
}
Loading

0 comments on commit f451d85

Please sign in to comment.