Referencing Serverless Output returns "[object Object]" instead of arn - serverless-framework

I'm using State Machines for the first time, and I'm having trouble referencing the State Machine arn in my Lambda function. I've tried following this article and the docs, but I must be missing something, because instead of the arn, I'm getting "[object Object]".
Environment Variable:
environment:
EMAIL_STATE_MACHINE: ${self:resources.Outputs.EmailQueueStateMachine.Value}
Output:
Outputs:
EmailQueueStateMachine:
Description: The ARN of the email delivery state machine
Value:
Ref: EmailQueueStateMachine
State Machine:
stepFunctions:
stateMachines:
ReportDeliveryEmailQueueStateMachine:
name: emailQueueStateMachine
id: EmailQueueStateMachine
dependsOn:
- EmailTemplatesDynamoDbTable
definition:
<definition>
Everything I've read has this same setup, so I know I must be missing something obvious.

Related

How to mix env variables with output variables in the environment declaration

So I have a env.yml file which lets me have a different variables for each stage:
provider:
name: aws
environment: ${file(env.yml):${opt:stage}}
I also need to share some output variables to Lambda which are declared like so:
Outputs:
UserPoolId:
Value:
Ref: QNABUserPool
Export:
Name: ${self:provider.stage}-UserPoolId
UserPoolClientId:
Value:
Ref: QNABUserPoolClient
Export:
Name: ${self:provider.stage}-UserPoolClientId
I've seen I can do this by adding this to my provider but this conflicts with my env.yml
environment:
COGNITO_USER_POOL_ID: ${cf:${self:service}-${self:provider.stage}.UserPoolId}
COGNITO_USER_POOL_CLIENT_ID: ${cf:${self:service}-${self:provider.stage}.UserPoolClientId}
I tried putting these into the env.yml but that didn't work:
Trying to request a non exported variable from CloudFormation. Stack name: "XXXX-alpha" Requested variable: "UserPoolId".
I tried using custom instead of environment and it deployed but the Lambda functions no longer had access to the variables.
So how can I mix these two together?
Thank you so much!
You can reference the Output values from your current service using the Fn::ImportValue function.
The serverless system adds sls-[service_name] to the variable but you can find them in the Outputs area of the CloudFormation Stack.
Navigate to CloudFormation --> Stacks --> [select your service] --> Outputs (tab). From there you'll see a column called Exports name.
Use that Exports name and use that for the import.
e.g. you have a WebSocket service and you need the service endpoint. If you look in the tab it will have an export ~ sls-wss-[your_service_name]-[stage]-ServiceEndpointWebsocket. Thus, you can import that into an environment variable:
Environment:
Variables:
ENDPOINT:
Fn::ImportValue: sls-wss-[your_service_name]-${opt:stage}-ServiceEndpointWebsocket

writing a cfn template to trigger fargate via cloudwatch events

I am unable to get TaskDefinitionArn in a variable .
I am trying to do the below:
cloudwatchTriggerForLambdaFunction:
Type: 'AWS::Events::Rule'
Properties:
Description: 'Trigger Lambda function according to the specified schedule'
ScheduleExpression: !Ref CronExpression
State: ENABLED
Targets:
- Arn: !Sub '${LambdaFunction.Arn}'
Id: cloudwatchTriggerForLambdaFunction
- Arn: !GetAtt FargateLauncher.Arn
Id: fargate-launcher
Input:
!Sub |
{
taskDefinition: "${TaskDefinitionArn}"
}
but the above throwing the error like below:
An error occurred (ValidationError) when calling the CreateStack operation: Template error: instance of Fn::Sub references invalid resource attribute TaskDefinitionArn.
I cannot get the value of TaskDefinitionArn in a parameter as this is going to be created runtime so must get this lie above. Pleae suggest some solution to this. Thanks in advance.
I had to change my approach a bit.
I am now using direct cloudwatch trigger on fargate task instead of running lambda function to trigger fargate task.
So that way, this query seems invalid.
If you try this way do try to create the arnanually like
**arn:aws:ecs:${AWS::AccountId}:${AWS:Region}**
Since your resource name is TaskDefinition, you should reference it by name.
{
taskDefinition: "${TaskDefinition}"
}
But according to this aws documentation, the ecs event rule should be defined as below
{
"Group" : String,
"LaunchType" : String,
"NetworkConfiguration" : NetworkConfiguration,
"PlatformVersion" : String,
"TaskCount" : Integer,
"TaskDefinitionArn" : String
}
therefore the key should be TaskDefinitionArn not taskDefinition. Please have a look at the reference.
I agree - but i am using this approach link below to run fargate task with cloudwatch trigger where he is using TaskDefinitionArn as a parameter. Which I don;t want to do. I want to get the value of Arn itself while running my task.
Let me know if you did not get my query.
creating a 'Target' for a cloudwatch event rule via cloudformation for a fargate launchtype task

what are drone.io 0.8.5 plugin/gcr secretes' acceptable values?

I'm having trouble pushing to gcr with the following
gcr:
image: plugins/gcr
registry: us.gcr.io
repo: dev-221608/api
tags:
- ${DRONE_BRANCH}
- ${DRONE_COMMIT_SHA}
- ${DRONE_BUILD_NUMBER}
dockerfile: src/main/docker/Dockerfile
secrets: [GOOGLE_CREDENTIALS]
when:
branch: [prod]
...Where GOOGLE_CREDENTIALS will work, but if named say GOOGLE_CREDENTIALS_DEV it will not be properly picked up. GCR_JSON_KEY works fine. I recall reading legacy documentation that spelled out the acceptable variable names, of which GOOGLE_CREDENTIALS and GCR_JSON_KEY were listed among other variants but as of version 1 they've done some updates omitting that info.
So, question is, is the plugin capable of accepting whatever variable name or is it expecting specific variable names and if so what are they?
The Drone GCR plugin accepts the credentials in a secret named PLUGIN_JSON_KEY, GCR_JSON_KEY, GOOGLE_CREDENTIALS, or TOKEN (see code here)
If you stored the credentials in drone as GOOGLE_CREDENTIALS_DEV then you can rename it in the .drone.yml file like this:
...
secrets:
- source: GOOGLE_CREDENTIALS_DEV
target: GOOGLE_CREDENTIALS
...

${} syntax in Serverless

On line 19 of this serverless.yml example, the following appears:
Resource: "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYNAMODB_TABLE}"
1) Is the syntax ${...} an instance of bash parameter expansion, like the expansion covered by this guide
2) In any case, what does the line above do?
Those are variable definitions. They can be defined somewhere else. Example
custom: ${file(env.yml)}
environment: ${self:custom.environment}
Then I define my variables in my env.yml as such
environment: dev
Resource: "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYNAMODB_TABLE}"
that resource is the resource arn for an example DYANMODB_TABLE
You would preform something like this
- Sid: "LogsAccess"
Effect: "Allow"
Action:
- "logs:CreateLogGroup"
- "logs:CreateLogStream"
- "logs:PutLogEvents"
- "logs:DescribeLogStreams"
Resource: "arn:aws:logs:*:*:*"
But in this case your block would relate to dynamodb.

What is "hellostepfunc1" in the serverless documenation for setup AWS stepfunctions?

In these documentation from the serverless website - How to manage your AWS Step Functions with Serverless and GiTHUb - serverless-step-functions, we can find this word hellostepfunc1: in the serverless.yml file. I could not find reference to it. I dont understand what is it, and I can't find any reference to it, even after the State Machine was created into AWS.
If I delete it I get the follow error
Cannot use 'in' operator to search for 'role' in myStateMachine
But if I change its name for someName for example I have no error and the State Machine will works good.
I could assume it is only an identifier but I not sure.
Where can I find reference to it?
This is quite specific to the library you are using and how it names the statemachine which is getting created based upon whether the name: field is provided under the hellostepfunc1: or not.
Have a look at the testcases here and here to understand better.
In-short a .yaml like
stateMachines:
hellostepfunc1:
definition:
Comment: 'comment 1'
.....
has name of statemachine like hellostepfunc1StepFunctionsStateMachine as no name was specified.
Whereas for a .yaml like
stateMachines:
hellostepfunc1:
name: 'alpha'
definition:
Comment: 'comment 1'
.....
the name of statemachine is alpha as you had name was specified.