yoges nsamy
05/30/2021, 4:57 AMIamRoleLambdaExecution: Syntax error in policy
encountered while deploying a lambda function to AWS.
(Additional info is added in the thread)
serverless.yml:
service: xxx-chat-api
provider:
name: aws
stackTags:
Team: Chat
runtime: go1.x
stage: ${opt:stage, 'dev'}
region: ap-southeast-1
timeout: 200
environment: ${file(env.yml)}
iamRoleStatements:
- ${file(models/chat.yml):consumerCognitoStatement}
- ${file(models/chat.yml):userCognitoStatement}
- ${file(models/chat.yml):adminTablePolicyStatement}
- ${file(models/chat.yml):sesStatement}
:
:
:
models/chat.yml:
consumerCognitoStatement:
Effect: "Allow"
Action:
- "cognito-idp:ListUsers"
- "lambda:InvokeFunction"
Resource:
- "${file(env.${self:provider.stage}.yml):COMPANY_COGNITO_RESOURCE_ARNS}"
- !Sub "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:xxx-cognito-auth-api-${self:provider.stage}-cogtoken"
userCognitoStatement:
Effect: "Allow"
Action:
- "cognito-idp:ListUsers"
- "lambda:InvokeFunction"
Resource: "${file(env.${self:provider.stage}.yml):USER_COGNITO_RESOURCE_ARNS}"
sesStatement:
Effect: Allow
Action:
- ses:SendEmail
- ses:SendRawEmail
Resource: "arn:aws:ses:eu-west-1:${AWS::AccountId}:identity/noreply@xxx.my"
COMPANY_COGNITO_RESOURCE_ARNS
has multiple values:
COMPANY_COGNITO_RESOURCE_ARNS:
# CO_1
- "arn:aws:cognito-idp:ap-southeast-1:xxx:userpool/ap-southeast-1_abc"
# CO_2
- "arn:aws:cognito-idp:ap-southeast-1:xxx:userpool/ap-southeast-1_xyz"
# CO_3
- "arn:aws:cognito-idp:ap-southeast-1:xxx:userpool/ap-southeast-1_jkl"
USER_COGNITO_RESOURCE_ARNS
has a single value:
USER_COGNITO_RESOURCE_ARNS:
# Secure:
- "arn:aws:cognito-idp:ap-southeast-1:xxx:userpool/ap-southeast-1_def"
Error: IamRoleLambdaExecution: Syntax error in policy
yoges nsamy
05/30/2021, 4:59 AMCOMPANY_COGNITO_RESOURCE_ARNS
COMPANY_COGNITO_RESOURCE_ARNS:
# CO_1
- "arn:aws:cognito-idp:ap-southeast-1:xxx:userpool/ap-southeast-1_abc"
yoges nsamy
05/30/2021, 4:59 AMyoges nsamy
05/30/2021, 5:01 AMmodel.yml
file was simpler without lambda:InvokeFunction
& sesStatement
(though now I realize these statements can be simplified)
consumerCognitoStatement:
Effect: "Allow"
Action:
- "cognito-idp:ListUsers"
Resource:
- "${file(env.${self:provider.stage}.yml):COMPANY_COGNITO_RESOURCE_ARNS}"
userCognitoStatement:
Effect: "Allow"
Action:
- "cognito-idp:ListUsers"
Resource: "${file(env.${self:provider.stage}.yml):USER_COGNITO_RESOURCE_ARNS}"
Frank
service: xxx-chat-api
provider:
name: aws
stackTags:
Team: Chat
runtime: go1.x
stage: ${opt:stage, 'dev'}
region: ap-southeast-1
timeout: 200
environment: ${file(env.yml)}
iamRoleStatements:
- Effect: "Allow"
Action:
- "cognito-idp:ListUsers"
- "lambda:InvokeFunction"
Resource:
- "arn:aws:cognito-idp:ap-southeast-1:xxx:userpool/ap-southeast-1_abc"
- "arn:aws:cognito-idp:ap-southeast-1:xxx:userpool/ap-southeast-1_xyz"
- "arn:aws:cognito-idp:ap-southeast-1:xxx:userpool/ap-southeast-1_jkl"
Frank
Frank
yoges nsamy
05/31/2021, 2:53 AMyoges nsamy
05/31/2021, 2:54 AMFrank