How I fix this one.
Error:
serverless.yml
provider:
name: aws
runtime: nodejs12.x
memorySize: 256
stage: ${opt:stage, 'dev'}
region: eu-west-1
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb.PutItem
Resource:
- arn:aws:dynamodb:#{AWS::Region}:#{AWS::AccountId}:table/AuctionsTable
I am new to aws services and serverless app development
when running sls deploy I am getting below error.
You have error in policy document, you used .(dot) in place of :(colon).
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:PutItem # use `:` here instead of `.`
Related
I am trying to deploy a serverless template using bitbucket pipeline. I have provided the sls deploy command as such sls deploy --stage ${environmentName} --cloudformationStackDynamoDB $dynamodbEventStoreStackName --componentName ${componentName} --partName ${partName} --eventBusName $eventBusName --region ${awsRegion} || exit
But I get this error when the pipeline reaches the step to deploy the serverless.yml file "Error:Cannot resolve serverless.yml: "service" property is not accessible (configured behind variables which cannot be resolved at this stage)"
Below is the content of serverless.yml
service:
name: ${opt:stage}-${opt:componentName}-${opt:partName}-stream
plugins:
- "#hewmen/serverless-plugin-typescript"
- serverless-plugin-resource-tagging
#- serverless-plugin-optimize
#- serverless-offline
# - serverless-plugin-warmup
# custom:
# # Enable warmup on all functions (only for production and staging)
# warmup:
# enabled: true
provider:
name: aws
runtime: nodejs16.x
stackName: ${self:service.name}
iamRoleStatements:
- Effect: Allow
Action:
- logs:Create*
- logs:Get*
Resource: "*"
- Effect: Allow
Action:
- dynamodb:*
Resource: "*"
- Effect: Allow
Action:
- events:PutEvents
Resource: "*" #TODO - apply pattern */eventbus-name
environment:
ENVIRONMENT: ${opt:stage}
COMPONENT_NAME: ${opt:componentName}
PART_NAME: ${opt:partName}
EVENTBUS_NAME: ${opt:eventBusName} #TODO - supply this as part of the CICD build
stackTags:
COMPONENT_NAME: ${opt:componentName}
STAGE: ${opt:stage}
functions:
default:
handler: src/lambda.streamHandler
name: ${self:provider.stackName}
events:
- stream: ${cf:${opt:cloudformationStackDynamoDB}.DynamoDBTableEventsStreamArn}
timeout: 30
I don't understand why the error says "service" property is not accessible because it is defined in the template file itself.
Any help would be appreciated.
Thanks!
I have a locally installed python module, which I am using in the lambda function. How should I include the local package while deploying to aws? I am using this framework
Here is my serverless.yml
service: lambda-daily-emails
frameworkVersion: '3'
plugins:
- serverless-python-requirements
custom:
pythonRequirements:
dockerizePip: 'non-linux'
package:
individually: true
patterns:
- '!.git'
- '!README.md'
- '!*.html'
- '!rough.py'
- '!sample-questions.json'
layers:
layerOne:
path: /absolute/location/of/package/repo
name: saral-utils-${opt:stage}
description: Saral utility package
include:
- ./**
provider:
name: aws
runtime: python3.8
stage: ${opt:stage}
region: ${env:MY_REGION}
iam:
role:
statements:
- Effect: Allow
Action:
- ses:SendEmail
- ses:SendRawEmail
- dynamodb:Get*
- dynamodb:Query
- dynamodb:Scan
Resource: "*"
functions:
emailer:
handler: handler.emailer
environment:
MY_ENV: ${env:MY_ENV}
MY_REGION: ${env:MY_REGION}
resources:
Resources:
invokeLambda:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:invokeFunction
FunctionName:
"Fn::GetAtt": [EmailerLambdaFunction, Arn]
Principal: events.amazonaws.com
I have tried with providing absolute location of package repo in the serverless.yml but it throws an error while deploying.
Error:
No file matches include / exclude patterns
I`m trying to upload lambda#edge with serverless but its not working, I cant see logs on the cloudwatch.
service: image-compress
frameworkVersion: '2'
plugins:
- serverless-bundle
provider:
name: aws
runtime: nodejs12.x
memorySize: 128
lambdaHashingVersion: '20201221'
stage: ${opt:stage, 'staging'}
environment:
ENV: ${self:provider.stage}
iamRoleStatements:
- Effect: "Allow"
Action:
- "s3:*"
Resource:
- "arn:aws:s3:::*"
functions:
image-reduce:
handler: handler.reducer
events:
- cloudFront:
eventType: origin-response
origin: s3://cropped-images-test2.s3.amazonaws.com/
isDefaultOrigin: true
custom:
bundle:
linting: false
packagerOptions:
scripts:
- npm install --arch=x64 --platform=linux sharp
This is the serverless yml, I can see this configuration on the cloudFront but I cant seem to get any logs when trying to receive images.
any help?
I am currently using the serverless-iam-roles-per-function plugin to give each of my lambda functions their own IAM roles. But when I deploy it, it seems like it still creates a default lambdaRole that contains all the functions. I did not define iamRoleStatements or VPC in the provider section of the serverless.yml. Am I missing something? I would like to only have roles per function. Any feedback would be appreciated.
Snippet of yml:
provider:
name: aws
runtime: go1.x
stage: ${env:SLS_STAGE}
region: ${env:SLS_REGION}
environment:
DB_HOSTS: ${env:SLS_DB_HOSTS}
DB_NAME: ${env:SLS_DB_NAME}
DB_USERNAME: ${env:SLS_DB_USERNAME}
DB_PASSWORD: ${env:SLS_DB_PASSWORD}
TYPE: ${env:SLS_ENV_TYPE}
functions:
function1:
package:
exclude:
- ./**
include:
- ./bin/function_1
handler: bin/function_1
vpc: ${self:custom.vpc}
iamRoleStatements: ${self:custom.iamRoleStatements}
events:
- http:
path: products
method: get
private: true
cors: true
authorizer: ${self:custom.authorizer.function_1}
custom:
vpc:
securityGroupIds:
- sg-00000
subnetIds:
- subnet-00001
- subnet-00002
- subnet-00003
iamRoleStatements:
- Effect: Allow
Action:
- lambda:InvokeFunction
- ssm:GetParameter
- ssm:GetParametersByPath
- ssm:PutParameter
Resource: "*"
I have below configuration on serverless.yml. But it doesn't deploy websocket connection. I wonder what could be wrong with my configuration. I have followed this instruction: https://www.serverless.com/framework/docs/providers/aws/events/websocket/
service:
name: ${opt:componentName}-api
plugins:
- '#hewmen/serverless-plugin-typescript'
provider:
name: aws
runtime: nodejs12.x
region: ap-southeast-2
websocketsApiName: custom-websockets-api-name
websocketApiRouteSelectionExpression: $request.body.action
stackName: ${opt:stage}-${self:service.name}
iamRoleStatements:
- Effect: Allow
Action:
- logs:Create*
- logs:Get*
Resource: "*"
- Effect: Allow
Action:
- dynamodb:*
Resource: "*"
functions:
wsHandler:
handler: src/websocketLambda.handleWebSocket
name: ${self:provider.stackName}-ws
evnets:
- websocket: $default
The output of serverless deploy is:
Serverless: Stack update finished...
Service Information
service: device-api-transactions-api
stage: dev
region: ap-southeast-2
stack: dev-device-api-transactions-api
resources: 6
api keys:
None
endpoints:
None
functions:
wsHandler: dev-device-api-transactions-api-ws
layers:
None
Serverless: Removing old service artifacts from S3...
Serverless: Run the "serverless" command to setup monitoring, troubleshooting and testing.