본문 바로가기

infra(terraform, aws, git)

terraform validation error: status code 400 in lambda creation

terraform을 생성하려고 할 때 위의 에러를 만날 수도, 만나지 않을 수도 있다.

 

그 이유는 잘 나타나지 않는 에러이기도 하면서, 단순한 에러이기도 하기 때문이다.

 

나 역시 같은 terraform 코드를 이용해 우리 회사에서는 잘 되던 것들이, on premise로 다른 회사에 적용 시키려고 할 때 이 같은 에러가 발생해서, 구글링을 열심히 했다.

 

일단 400대의 코드를 보니 요청을 잘못했음을 알 수 있으며, 구글링 결과, terraform은 자세한 에러를 표시해주지 않고, 두리뭉실하게 표현하는 경향이 있다고 한다.

 

그래서 직접 에러를 자세히 보기 위해 aws cli를 이용해 lambda function을 생성해보도록 했다.

 

master@www:~$ aws lambda create-function --function-name staging-data-sync --role \
arn:aws:iam::xxxxxxxxxxxx:role/staging-iam-data-sync-role --timeout 900 --memory-size 10240 \
--package-type Image --code ImageUri=xxxxxxxxxxx.dkr.ecr.ap-northeast-2.amazonaws.com/xxxxxx/\
lambda/data-sync:staging-latest --profile xxxxxxx

 

그랬더니 다음과 같은 에러가 떴다.

 

우리는 memory size가 10240인데 반해 on premise를 진행하던 회사의 size는 3008 이하여야한다고 에러를 보내는 모습이다. 그래서 일단 memory size를 2048로 전부 바꿔 진행했더니 성공적으로 됬다.

 

그렇다면 왜 계정마다 memory size가 다른 것일까?

 

 그에 대한 해답은 여기에 있다.

https://stackoverflow.com/questions/70943739/aws-lambda-memorysize-value-failed-to-satisfy-constraint

 

AWS Lambda: 'MemorySize' value failed to satisfy constraint

I have a really weird problem while trying to change Lambda's memory size. It's clearly stated in the UI that we can Set memory to between 128 MB and 10240 MB, but when I set 8192 value and click A...

stackoverflow.com

 

간략하게 말하면, lambda function을 처음 사용한다면 바로 10기가 사용하지 말고 좀 적게 사용한 다음, 많이 사용하면 그 때 올려준다는 말이다.