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?
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!
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 `.`
I'm currently learning Serverles Framework with AWS. However in the serveless.yml I getting an error with some imports files. Is there any guidance to achieve imports from a different file?
AuctionsTable: ${file(resources/AuctionsTable.yml):AuctionsTable} path is located in the same level of the serverless one.
serveless.yml
service:
name: auction-service
plugins:
- serverless-bundle
- serverless-pseudo-parameters
provider:
name: aws
runtime: nodejs12.x
memorySize: 256
stage: ${opt:stage, 'dev'}
region: eu-west-1
iamRoleStatements:
- ${file(iam/AuctionsTableIAM.yml):AuctionsTableIAM}
resources:
Resources:
AuctionsTable: ${file(resources/AuctionsTable.yml):AuctionsTable}
functions:
createAuction:
handler: src/handlers/createAuction.handler
events:
- http:
method: POST
path: /auction
custom:
bundle:
linting: false
I have created AWS Lambda function to run when new fils in S3 at specific path is created, which works perfectly.
service: redshift
frameworkVersion: '2'
custom:
bucket: extapp
path_prefix: 'xyz'
database: ABC
schema: xyz_dbo
table_prefix: shipmentlog
user: admin
password: "#$%^&*(*&^%$%"
port: 5439
endpoint: "*********.redshift.amazonaws.com"
role: "arn:aws:iam::*****:role/RedshiftFileTransfer"
provider:
name: aws
runtime: python3.8
stage: prod
region: us-west-2
stackName: redshift-prod-copy
stackTags:
Service: "it"
lambdaHashingVersion: 20201221
memorySize: 128
timeout: 900
logRetentionInDays: 14
environment:
S3_BUCKET: ${self:custom.bucket}
S3_BUCKET_PATH_PREFIX: ${self:custom.path_prefix}
REDSHIFT_DATABASE: ${self:custom.database}
REDSHIFT_SCHEMA: ${self:custom.schema}
REDSHIFT_TABEL_PREFIX: ${self:custom.table_prefix}
REDSHIFT_USER: ${self:custom.user}
REDSHIFT_PASSWORD: ${self:custom.password}
REDSHIFT_PORT: ${self:custom.port}
REDSHIFT_ENDPOINT: ${self:custom.endpoint}
REDSHIFT_ROLE: ${self:custom.role}
iam:
role:
name: s3-to-redshift-copy
statements:
- Effect: Allow
Action:
- s3:GetObject
Resource: "arn:aws:s3:::${self:custom.bucket}/*"
functions:
copy:
handler: handler.run
events:
- s3:
bucket: ${self:custom.bucket}
event: s3:ObjectCreated:*
rules:
- prefix: ${self:custom.path_prefix}/
- suffix: .json
existing: true
package:
exclude:
- node_modules/**
- package*.json
- README.md
plugins:
- serverless-python-requirements
But when I deployed this function, there was also another function get deployed with name redshift-prod-custom-resource-existing-s3 which is Node.js function. I want to understand why this second function necessary for triggering primary lambda function when new file is creates in S3 bucket at specific path.
It's the serverless Framework's method of adding the trigger to call the lambda to the S3 bucket via a Custom 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.