Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform apply fails with error creating Lambda Event Source Mapping #138

Open
ofhouse opened this issue Jun 15, 2021 · 6 comments
Open
Labels
bug Something isn't working
Milestone

Comments

@ofhouse
Copy link
Member

ofhouse commented Jun 15, 2021

When setting up a new Next.js app with 0.9.0, the first apply may fail with the following error message:

Error: error creating Lambda Event Source Mapping (arn:aws:sqs:eu-central-1:430654418481:terraform-next-js-existing-cloudfront20210615141542329600000006): InvalidParameterValueException: The provided execution role does not have permissions to call ReceiveMessage on SQS
│ {
│   RespMetadata: {
│     StatusCode: 400,
│     RequestID: "a08ca594-80e3-4db8-8176-dc140f31565a"
│   },
│   Message_: "The provided execution role does not have permissions to call ReceiveMessage on SQS",
│   Type: "User"
│ }
│ 
│   with module.tf_next.module.statics_deploy.module.deploy_trigger.aws_lambda_event_source_mapping.this["sqs_source"],
│   on .terraform/modules/tf_next.statics_deploy.deploy_trigger/main.tf line 211, in resource "aws_lambda_event_source_mapping" "this":
│  211: resource "aws_lambda_event_source_mapping" "this" {

It seems like there is some race condition when the policy for the Lambda is created.

Workaround

You should be able to runterraform apply again and the stack creation would progreed without this error.

@ofhouse ofhouse added the bug Something isn't working label Jun 15, 2021
@ofhouse
Copy link
Member Author

ofhouse commented Jun 19, 2021

Another error that can pop up:

╷
│ Error: error putting S3 Bucket Notification Configuration: InvalidArgument: Unable to validate the following destination configurations
│       status code: 400, request id: 1ZS0PHX7B4ZBZ8M8, host id: kkKv9mk5ouVUJxrmXYs0Wu2xIJ3YFNfib0yyC/8XvhkYfBVPoETA+HPzUP/LAuNrMcqdOX/IDiQ=
│ 
│   with module.tf_next.module.statics_deploy.aws_s3_bucket_notification.on_create,
│   on ../../modules/statics-deploy/main.tf line 22, in resource "aws_s3_bucket_notification" "on_create":
│   22: resource "aws_s3_bucket_notification" "on_create" {
│ 
╵

@thirdender
Copy link

Using depends_on = [ aws_iam_role_policy_attachment.EXAMPLE ] doesn't seem to fix the problem either.

@ofhouse
Copy link
Member Author

ofhouse commented Aug 12, 2021

Yes, the problem is probably caused because we use SQS and S3 als event source for a single Lambda.
To solve this issue the S3 workflow should also be connected to the SQS queue so that the Lambda is only invoked by SQS.

@IzioDev
Copy link

IzioDev commented Feb 12, 2022

I had a similar issue. I was using pnpm, do I didn't use yarn or npm at all.
The worst part is that my packages use workspace dependencies, hence unresolvable by yarn nor npm. (pnpm workspace..)

Is it possible to not rely on yarn or npm ? I saw the code source underneath and it seems like next build function is using yarn or npm under the hood with a weird detection method (scrapping files, looking for a package-lock.json or yarn.lock)

@gipsen92
Copy link

gipsen92 commented Aug 24, 2022

i can confirm this bug on 1.0.0-canary.5 and the workaround is working fine.
thanks.

@ranikaruna
Copy link

Another error that can pop up:

╷
│ Error: error putting S3 Bucket Notification Configuration: InvalidArgument: Unable to validate the following destination configurations
│       status code: 400, request id: 1ZS0PHX7B4ZBZ8M8, host id: kkKv9mk5ouVUJxrmXYs0Wu2xIJ3YFNfib0yyC/8XvhkYfBVPoETA+HPzUP/LAuNrMcqdOX/IDiQ=
│ 
│   with module.tf_next.module.statics_deploy.aws_s3_bucket_notification.on_create,
│   on ../../modules/statics-deploy/main.tf line 22, in resource "aws_s3_bucket_notification" "on_create":
│   22: resource "aws_s3_bucket_notification" "on_create" {
│ 
╵

So what is the workaround for this issue?
I'm seeing the same while trying to configure an event notification with sns topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants