-
Are you certain it's a bug?
Is the issue caused by a plugin?
Are you using the latest version?
Is there an existing issue for this?
Issue descriptionMoments ago, I update my packages to latest version. And trying to learn the app locally. I am getting error: Update from old to newMy env filesService configuration (serverless.yml) contentservice: serverless-aws-graphql-book
package:
individually: true
include:
- src/**
provider:
name: aws
profile: ${env:profile}
runtime: nodejs14.x
stage: ${env:stage}
region: eu-north-1
timeout: 30
apiName: ${self:service.name}-${self:provider.stage}
environment:
ITEM_TABLE: ${self:service}-items-${self:provider.stage}
COGNITO: ${self:service.name}-pool
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
- lambda:InvokeFunction # Added this like mentioned above
Resource: 'arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.ITEM_TABLE}'
- Effect: Allow
Action:
- dynamodb:Query
Resource: 'arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.ITEM_TABLE}/index/*'
apiGateway:
shouldStartNameWithService: true
custom:
webpack:
webpackConfig: ./webpack.config.js
includeModules: true
packager: 'npm' # Packager that will be used to package your external modules
warmup:
enabled: true
events:
- schedule: rate(5 minutes)
prewarm: true
concurrency: 1
prune:
automatic: true
number: 5
functions:
graphql:
handler: src/handlers/graphql.default
events:
- http:
path: ${env:api_prefix}/graphql
method: get
cors: true
- http:
path: ${env:api_prefix}/graphql
method: post
cors: true
authorizer: AuthFunction
## Authorization function
AuthFunction:
handler: src/auth/auth.default
## Create user
PreSignUp:
handler: src/handlers/PreSignUp.default
events:
- cognitoUserPool:
pool: ${self:provider.environment.COGNITO}
trigger: PreSignUp
existing: true
resources:
Resources:
ItemsTable:
Type: 'AWS::DynamoDB::Table'
Properties:
AttributeDefinitions:
- AttributeName: PK
AttributeType: S
- AttributeName: SK
AttributeType: S
- AttributeName: GSI1PK
AttributeType: S
- AttributeName: GSI1SK
AttributeType: S
KeySchema:
- AttributeName: PK
KeyType: HASH
- AttributeName: SK
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
GlobalSecondaryIndexes:
- IndexName: GSI1
KeySchema:
- AttributeName: GSI1PK
KeyType: HASH
- AttributeName: GSI1SK
KeyType: RANGE
Projection:
ProjectionType: ALL
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TableName: ${self:provider.environment.ITEM_TABLE}
CognitoUserPool:
Type: AWS::Cognito::UserPool
Properties:
MfaConfiguration: OFF
UserPoolName: ${self:provider.environment.COGNITO}
UsernameAttributes:
- email
Policies:
PasswordPolicy:
MinimumLength: 6
RequireLowercase: False
RequireNumbers: True
RequireSymbols: False
RequireUppercase: True
useDotenv: true
plugins:
- serverless-webpack
- serverless-offline
- serverless-plugin-warmup
- serverless-dotenv-plugin
- serverless-prune-plugin Command name and used flagsnpm run serv Command output"N/A" Environment information{
"name": ".....",
"version": "1.0.1",
"main": "src/handler.js",
"license": "MIT",
"scripts": {
"deploy": "sls deploy --stage development",
"deploy:production": "sls deploy --stage production",
"lint": "eslint src --ext ts,js --no-ignore --fix",
"serve": "sls offline -P 4000",
"start": "node -e js,ts,jsx,tsx -x npm run serve",
"test": "jest",
"test:watch": "jest --watch",
"build": "sls webpack",
"setup": "./bin/setup",
"graphql-codegen": "graphql-codegen --config codegen.yml"
},
"devDependencies": {
"@graphql-codegen/cli": "^2.6.2",
"@graphql-codegen/typescript": "^2.4.7",
"@types/aws-lambda": "^8.10.93",
"@types/jest": "^25.2.3",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^3.10.1",
"@typescript-eslint/parser": "^3.10.1",
"aws-sdk": "^2.1090.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.15.0",
"husky": "^4.3.8",
"lint-staged": "^10.5.4",
"nodemon": "^2.0.0",
"prettier": "^2.5.1",
"serverless": "^3.7.5",
"serverless-dotenv-plugin": "^3.12.2",
"serverless-offline": "^8.5.0",
"serverless-plugin-warmup": "^7.1.0",
"serverless-prune-plugin": "^2.0.1",
"serverless-webpack": "^5.6.1",
"ts-jest": "^25.5.1",
"ts-loader": "^6.2.2",
"typescript": "^3.6.3",
"webpack": "^4.46.0",
"webpack-node-externals": "^1.7.2"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"src/**/*.{js,ts}": [
"npm run lint",
"prettier --write",
"git add"
]
},
"dependencies": {
"apollo-server-core": "^3.5.0",
"apollo-server-lambda": "^3.5.0",
"aws-lambda": "^1.0.7",
"graphql": "^15.8.0",
"ramda": "^0.28.0",
"uuid": "^8.3.2"
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 9 replies
-
Hello @alakdam07 - I'm moving it to discussions as it's not a bug report. You migrated two major versions and in the meantime, there was a change in how the variable resolver works. In your case, stage is not available as an environment variable so resolution of it fails. Either make sure it's defined or provide a default value e.g. |
Beta Was this translation helpful? Give feedback.
-
HI, @pgrzesik . Am also getting the same issue while running the sreverless deploy from aws code build. if we ran the command manually it is working but while using buildspec file to run it is not getting the details from env file. below are the error am getting while running the build. please help me with any suggestion [Container] 2022/04/04 10:41:59 Phase complete: INSTALL State: SUCCEEDED116 | [Container] 2022/04/04 10:41:59 Phase context status code: Message: |
Beta Was this translation helpful? Give feedback.
-
@pgrzesik Sorry for that... first let me tell what I did... Am a devops engineer working on AWS platform.. Here our dev team wrote this code and run successfully in their local machine... when we try to automate it we are facing this issue. Am also not sure why they are using this flag. Two major issue we are facing
I think both issues are related to one another. If got any input from u guys it will be very helpful. Thanks in Advance. |
Beta Was this translation helpful? Give feedback.
-
@pgrzesik @alakdam07 Happy Coding!service: ${self:custom.serviceName.${self:custom.stage}} #picks service name based on env frameworkVersion: '2' custom: provider: functions: plugins:
@pgrzesik Yes the .env is in root path. I didnt get this one (I'm assuming you somehow create the .env file on CodeBuild, right?) clearely. we write and store the .env file in codecommit repository. while creating the build using codebuild i need to get the variables from .env and want to inject those values to the lambda function. |
Beta Was this translation helpful? Give feedback.
-
@pgrzesik THank you much for your support on this. now it is working. after modifying the command you told i ran into some permission issues that i solved and working fine... meanwhile our dev team worked on another branch done some modification in serverless file to make it work and that solution also working but that takes lot of coding than before. I will cross check once again and will suggest which method will be good for the future... And one more |
Beta Was this translation helpful? Give feedback.
-
@pgrzesik or anyone, I need some help here. Please am currently have this same issue. Console Output
Error:
and my Jenkinsfile looks like below:
Kindly advise on how i can resolve this. |
Beta Was this translation helpful? Give feedback.
-
I know this isn't the fix but you could programatically export the environment variable, I still kept my .env file and updated my deploy script as following,
|
Beta Was this translation helpful? Give feedback.
-
adding below line of code helped me source : https://www.serverless.com/framework/docs/environment-variables |
Beta Was this translation helpful? Give feedback.
Hello @alakdam07 - I'm moving it to discussions as it's not a bug report. You migrated two major versions and in the meantime, there was a change in how the variable resolver works. In your case, stage is not available as an environment variable so resolution of it fails. Either make sure it's defined or provide a default value e.g.
${env:stage, 'dev'}
. In general, I would not recommend reading stage from env vars as the env files are recognized per stage.