I inherited a PHP project and it's heavily integrated with AWS SDK v2. Using v3 is not an option at this time.
My question is how can I leverage SNS to send text messages to specific numbers as needed? That is, I don't want to send mass notifications to a bunch of phone numbers subscribed to a specific topic when an action occurs, I want to send a notification to a specific phone number when an action occurs.
I came across this https://stackoverflow.com/a/41268045/664881 but it appears to be using v3 of the AWS SDK. Is there an equivalent with v2 of the AWS SDK?
I managed to make it work in PHP AWS SDK v2, but you need to add new parameter in the source code.
// update file: aws-sdk-php/src/Aws/Sdk/Resources/sns-2010-03-31.php
'Publish' => array(
'parameters' => array(
'PhoneNumber' => array( // new parameter
'type' => 'string',
'location' => 'aws.query',
),
),
),
// You just need to publish it and include the `PhoneNumber` parameter
$snsClientResult = $snsClient->publish([
'Message' => 'YOUR_MESSAGE',
'PhoneNumber' => 'PHONE_NUMBER',
'MessageStructure' => 'SMS',
'MessageAttributes' => [
'AWS.SNS.SMS.SenderID' => [
'DataType' => 'String',
'StringValue' => 'SENDER_ID',
],
'AWS.SNS.SMS.SMSType' => [
'DataType' => 'String',
'StringValue' => 'Promotional', // Transactional
]
]
]);
// Get the response
$snsClientResult['MessageId']
Related
I am using amazon PHP SDK to try to send sms I am using following code:
<?php
require 'vendor/autoload.php';
$sdk = new Aws\Sns\SnsClient([
'region' => 'eu-west-1',
'version' => 'latest',
'credentials' => ['key' => 'xxx', 'secret' => 'xxx']
]);
$result = $sdk->publish([
'Message' => 'This is a test message.',
'PhoneNumber' => '+123456789',
'MessageAttributes' => ['AWS.SNS.SMS.SenderID' => [
'DataType' => 'String',
'StringValue' => 'testing sms'
]
]]);
print_r( $result );
My question is how do I get delivery Status back to an endpoint url HTTPS or HTTP?
like the sms got delivered or failed? any idea?
The only way to do this today is to leverage the CloudWatch API (e.g. https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_GetLogEvents.html) to read the logs delivered to your log groups
I'm trying to make a copy of work items (Tasks, etc.) from one location to another in Azure DevOps, using PHP and Laravel. I was able to send data in JSON format to the Azure API and create a task (according to the example posted). I can't make a copy. Can you help me?
Route::get('/add_work_item', function () {
$response = Http::withBasicAuth('{key}', '{PAT}')
->withHeaders([
'Content-Type' => 'application/json-patch+json'
])
->post('https://dev.azure.com/{Organisation}/{Project}/_apis/wit/workitems/$Task?api-version=5.1', [
[
'op' => 'add',
'path' => '/fields/System.Title',
'from' => null,
'value' => 'New Task'
],
[
'op' => 'add',
'path' => '/fields/System.AreaPath', 'from' => null, 'value' => '{Project}'
]
]);
return dd(json_decode($response->getBody()));
});
I've been tasked with figuring out how the AWS PHP sdk works so we can possibly use it for hosting customer image data for our web server. I've been able to successfully test most of the functionality of creating, managing and loading data into a bucket, but when I try to view the contents I get 'access denied'.
Going into the management console, I figured out how to set the permissions so I could view the file, either with a specific host rule or by setting both the bucket and the object world-readable.
However, no matter how I try following the examples in the PHP sdk [limited] documentation, I cannot seem to set the ACL values using the php code provided by Amazon.
Their examples just list in the place of the various value and I have tried filling in the relevant data for my bucket, object and account in those and it doesn't work. I've tried doing a getObjectAcl and sending back something similar to what was received and it doesn't work. I've tried looking at examples on-line and what little I have found doesn't work.
Here's an example of the latest I have tried:
$params = [
'ACL' => 'public-read',
'AccessControlPolicy' => [
'Grants' => [
[
'Grantee' => [
'DisplayName' => 'Owner',
'ID' => $awsId,
'Type' => "CanonicalUser"
],
'Permission' => "FULL_CONTROL"
],
[
'Grantee' => [
'DisplayName' => 'All Users',
'URI' => "http://acs.amazonaws.com/groups/global/AllUsers",
'Type' => "Group"
],
'Permission' => "READ"
],
],
'Owner' => [
'ID' => $awsId
]
],
'Bucket' => "our-test-bucket",
'Key' => "800x600.jpg"
];
$result = $awsSdk->getS3Client()->putObjectAcl($params);
The resulting output:
Fatal error: Uncaught exception 'Aws\S3\Exception\S3Exception' with
message 'Error executing "PutObjectAcl" on
"https://our-test-bucket.s3.us-east-2.amazonaws.com/800x600.jpg?acl";
AWS HTTP error: Client error: PUT
https://our-test-bucket.s3.us-east-2.amazonaws.com/800x600.jpg?acl
resulted in /project/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php
on line 191
Aws\S3\Exception\S3Exception: Error executing "PutObjectAcl" on "https://our-test-bucket.s3.us-east-2.amazonaws.com/800x600.jpg?acl";
AWS HTTP error: Client error: PUT
https://our-test-bucket.s3.us-east-2.amazonaws.com/800x600.jpg?acl
resulted in a 400 Bad Request response:
MalformedACLErrorThe XML you provided was not well-f (truncated...)
MalformedACLError (client): The XML you provided was not well-formed or did not validate against our published schema -
MalformedACLErrorThe XML you provided was not well-formed or did not validate against our published
schemaB24661919936C2DADft/***********************************************= in /project/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php on line
191
I managed to drop a trace into the guzzle html messageTrait withHeader() function so I could watch the outgoing xml in the php stream. I then compared the result with examples of the xml I found in various places in a google search and through trial and error with the comparisons, I traced the problem down to the 'DisplayName' => 'All Users' in the Group Grant. Remove that line and it appears to work.
$pubAcl = [
'Owner' => [
'ID' => $awsId,
'DisplayName' => 'Owner'
],
'Grants' => [
[
'Grantee' => [
'ID' => $awsId,
'DisplayName' => 'Owner',
'Type' => "CanonicalUser"
],
'Permission' => "FULL_CONTROL"
],
[
'Grantee' => [
'URI' => "http://acs.amazonaws.com/groups/global/AllUsers",
'Type' => "Group"
],
'Permission' => "READ"
]
]
];
(The order change was the result of testing but didn't turn out to be the problem)
I'm launching an AWS instance using the PHP SDK and everything works well except I'm not able to set the name(tag) of that instance.
Here is my code:
$result_create_instance = $ec2_client->runInstances([
'AdditionalInfo' => 'notihng',
'ImageId' => $aws_ami, // REQUIRED
'MaxCount' => 1, // REQUIRED
'MinCount' => 1, // REQUIRED
'InstanceType' => $aws_instance_type,
'Monitoring' => [
'Enabled' => true // REQUIRED
],
'UserData' => $user_Data,
'SubnetId' => 'subnet-125cxxxx',
'SecurityGroupIds' => ['sg-5axxxxx'],
'TagSpecification` => [
'ResourceType' => 'instance',
'Tags' => [ 'Key' => 'Name',
'Value'=>'my instance'
],
],
]);
Any suggestion will be appreciated.
Thanks
The parameter should be TagSpecifications with an s not TagSpecification. Also make sure you are using a recent version of the AWS SDK since adding tags at launch is a fairly new feature.
I am sending a post request to the GetResponse API. Everything works fine until I add a custom field (customFieldValues) to save along with my new email contact.
$body_data =
[
'name' => $input['name'],
'email' => $input['email'],
'campaign' => [
'campaignId' => $campaign_id
],
'customFieldValues' => ['customFieldId' => 'LDe0h', 'value' => ['Save this test string.'] ]
];
When I send the request I get the following error message:
"errorDescription": "CustomFieldValue entry must be specified as array"
I have tried a few things now and not sure how to format this properly to have the API accept it.
Reference link:
http://apidocs.getresponse.com/v3/case-study/adding-contacts
I found the solution on github in an example for their php api here:
https://github.com/GetResponse/getresponse-api-php
I suppose I had to wrap an array inside an array inside of an array...geez:
'customFieldValues' => array(
array('customFieldId' => 'custom_field_id_obtained_by_API',
'value' => array(
'Y'
)),
array('customFieldId' => 'custom_field_id_obtained_by_API',
'value' => array(
'Y'
))
)
For GetResponse V3
'customFieldValues' => [
'customFieldId' => 'custom_field_id_from_API',
'name' => 'Website',
'value' => ['https://scholarshipspsy.com']
]
Please note the 'name' field is optional. The site sampled is an international scholarship platform.