Hi! I might need a hand on this one! I am trying t...
# typescript
r
Hi! I might need a hand on this one! I am trying to create/update a callbackFunction:
Copy code
import * as aws from '@pulumi/aws';
import * as pulumi from '@pulumi/pulumi';
import { v4 as uuid } from 'uuid';

import { CognitoUserPoolTriggerEvent } from 'aws-lambda';

const name = 'mylambda';

const partitionRole = new aws.iam.Role(
  `${name}-lambda-role`, {
    assumeRolePolicy: JSON.stringify({
      "Version": "2012-10-17",
      "Statement": [
        {
            "Action": "sts:AssumeRole",
            "Principal": {
                "Service": "<http://lambda.amazonaws.com|lambda.amazonaws.com>",
            },
            "Effect": "Allow",
            "Sid": "",
        },
      ],
    })
  },
);

const attachment = new aws.iam.RolePolicyAttachment(
  `${name}-lambda-role-attachment`, {
    role: partitionRole,
    policyArn: aws.iam.ManagedPolicies.AWSLambdaFullAccess,
  },
  { dependsOn: [ partitionRole ] },
);

const preTokenLambda = new aws.lambda.CallbackFunction<CognitoUserPoolTriggerEvent, CognitoUserPoolTriggerEvent>(
  name, {
    name: `${name}-lambda-${uuid()}`,
    description: "lambda.",
    role: partitionRole,
    runtime: aws.lambda.NodeJS12dXRuntime,
    memorySize: 128,
    timeout: 30,
    reservedConcurrentExecutions: 50,
    callback: async (event) => {
      event.response.claimsOverrideDetails = {
        claimsToAddOrOverride: {
          role: 'member',
          bla: 'yes',
        },
      };
      return event;
    },
  },
  { dependsOn: [ partitionRole, attachment ]  },
);
I am forcing the lambda to recreate including a uuid in its name. It uploads it correctly but then I consistently get a
function already exist
error
Copy code
+  aws:lambda:Function pool creating error: Error creating Lambda function: ResourceConflictException: Function already exist: pool-lambda-80a6da40-c917-41c9-90d8-7cef62a40dcc
any ideas?
more details:
Copy code
{
      RespMetadata: {
        StatusCode: 409,
        RequestID: "4571dacb-8e3b-42e1-bcc3-3ee762eb560c"
      },
      Message_: "Function already exist: pool-lambda-80a6da40-c917-41c9-90d8-7cef62a40dcc",
      Type: "User"
    }
409 response is
Copy code
ResourceConflictException
The resource already exists, or another operation is in progress.

HTTP Status Code: 409
w
That error is coming from AWS - so it seems like somehow you have created a lambda with that same name. Are you trying to force this to be replaced on every update? I can’t exactly follow the desired replacement behavior. I don’t think it’s actually what you want - but you could try
deleteBeforeReplace.
👍 1
r
FYI I switched from inline lambda to s3 based lambda - and it worked fine. I suspect that my node_modules was too big (although it was around 5MB) hence failing weirdly after the upload.